I have an object that is to perform an action, and then sleep for 1 second before performing the action again. However, the object has variables that need to be accessible at all times regardless if it is in its one second sleep period. Is when the object’s execution is suspended, are its variables inaccessible?
This is Python.
Thanks.
EDIT 1:
Clarifying ‘inaccessible’:
Object A has variable x that Object B needs to access repeatedly.
Object A sleeps for 1 second. Will there be a problem if Object B tries to use x while A is sleeping?
EDIT 2:
Forgot to mention the two objects are running as individual processes (I’m using processes to avoid the GIL)
EDIT 3:
class QueueController(Process):
def __init__(self):
Process.__init__(self)
self.queue_stream = Queue()
self.queue_language = Queue()
self.queue_expander = Queue()
self.queue_feature = Queue()
self.queue_classify = Queue()
self.db = connect_to_db()
def run(self):
# Every second, allow 10 more tweets from the raw_tweets db
# enter the queue_stream to be processed
value = 0
while True:
for i in db.raw_tweets.find().skip(value).limit(30):
self.queue_stream.put(i)
value+=30
sleep(1)
Will another object who uses this QueueController class still be able to use the ‘queues_’ variables even when it sleeps for one second? I’m afraid that sleeping stops execution, but also access to those queue_ variables as a side affect.
time.sleep()does release the GIL, so other threads will be allowed to run.The reason I give this answer instead of answering the question you’ve asked is that the question you’ve asked makes no sense. No access is ever prevented other than the ability for other threads to run.