Essentially, the variable 'exists' doesn't return. The output is "false, true, false," but I cannot see why it should be. As can be seen from the code, I have tried making the variable 'exists' global
to no effect.
I've looked around and found two similar questions- Python--Function not returning value, Python: Return possibly not returning value, but cannot understand why my code doesn't work.
I'm aware that this question is very specific- if it's a silly mistake I've missed then I'll remove it, if it's a Python caveat then I'll see whether I can rephrase it.
import time
global exists
exists= False
def in_thread(exists):
print(exists)
time.sleep(2)
exists= True
print(exists)
return(exists)
in_thread(exists)
print(exists)