'How to detect if a global variable is changed in another python file and use this variable
I'm working on a school project in which i need to run a few programs at the same time. I do this with subprocess.Popen in python. However, one of these subprocesses needs a global variable from another subprocess. When i import the variable to the file that needs it, it will be correct, but when this global variable is updated in the original file, the other file won't automatically update it there too. I have tried putting the from ... import ... in the while True loop, but that didn't seem to work, since the variable is only imported once.
for example:
main.py:
process_lcd_screen = subprocess.Popen(["python", "Project_LCD_Screen.py"])
process_lamp = subprocess.Popen(["python", "Project_lamp.py"])
process_lcd_screen.wait()
process_lamp.wait()
Project_LCD_Screen.py:
while True:
from Project_lamp import lamp_status
print(lamp_status)
Project_lamp.py:
lamp_status = False
while True:
if (something here == True):
lamp_status = True
else:
lamp_status = False
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
