I have global variable that I'd like to access from thread and from main program:
import thread
var = 0
def abc(lock):
lock.acquire()
var = 1
lock.release()
lock = thread.allocate_lock()
thread.start_new_thread(abc, (lock))
while True:
#should I put lock.acquire() here?
var = 2
#and should I put lock.realease() here?
I would imagine something like this. At least I do it that way with only threads (by the way - is it OK to pass lock into thread like that? I do that with all of them). If it is not possible the only way is to put main code into thread too?