The y.py
script runs continuously and updates the z
variable. I need to access the z
variable through
x.py
, and it does not work. I am trying to use two different threads.
y.py
import threading
# Run every 3 seconds to update the z variable
if __name__ == "__main__": # Should avoid the importation to modify the z variable content
delay = 3
z = 0
def foo():
global z
z = z + 1
print("inner",z)
# This thread run continuously and should not
# block the other threads
threading.Timer(delay,foo).start()
foo()
print("outer",z + 10)
x.py
import y
foo = y.z
print(foo)