I have a script written in python 2.7 that calls for a thread. But, whatever I do, the thread won't call the function.
The function it calls:
def siren_loop():
while running:
print 'dit is een print'
The way I tried to call it:
running = True
t = threading.Thread(target=siren_loop)
t.start()
or:
running = True
thread.start_new_thread( siren_loop, () )
I even tried to add arguments to siren_loop to see if that would work, but no change. I just can't get it to print the lines in the siren_loop function.
I also tried many other strange things, which obviously didn't work. What am I doing wrong?
edit: Since people said it worked, I tried to call the thread from another function. So it looked something like this:
def start_sirene():
running = True
t = threading.Thread(target=siren_loop)
t.start()
And then that part was called from:
if zwaailichtbool == False:
start_sirene()
print 'zwaailicht aan'
zwaailichtbool = True
sleep(0.5)
Maybe that could cause the problem? The print statement in the last one works, and when I added a print before or after the thread statement it also worked.
siren_loopcontinuously. So I'm not sure what the problem is.zwaailichtboolis not False?