我有一个fileA.py
基于 GPIO 触发器控制无线电演播室照明的主文件。我关心的部分是在一个 While True 循环中,如下所示:
While True:
#other triggers for other things unrelated
if GPIO.input(25) == GPIO.LOW and (state) = 'off':
blue()
studiostatus = "online"
#other triggers for other things unrelated
elif count > 7200:
dbo()
clockoff()
studiostatus = "offline"
然后我fileB.py
在同一个 Raspberry Pi 上同时运行第二个 python 文件
import SocketServer
from BaseHTTPServer import BaseHTTPRequestHandler
def some_function():
print "some_function got called"
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/doorbell':
some_function()
self.send_response(200)
httpd = SocketServer.TCPServer(("", 8080), MyHandler)
httpd.serve_forever()
但是我希望它能够不断更新studiostatus
变量 fromfileA.py
以便行fileB.py
变为
if self.path == '/doorbell' and studiostatus = "online":
action1()
elif self.path == '/doorbell' and studiostatus = "offline":
action2()
任何帮助都非常感谢,因为目前我看不到树木的木材如何最好地解决这个问题