0
我有一個程序,它需要在後臺連續運行,但能夠接收到要更改的指令。我有這個線程運行,將數據發送到一個Arduino和接收數據傳回:從外部控制python線程
class receiveTemp (threading.Thread):
def __init__(self, out):
threading.Thread.__init__(self)
self.out = out
def run(self):
self.alive = True
try:
while self.alive:
rec = send("command")
self.out.write(rec)
except BaseException as Error:
print(Error)
pass
現在我需要改變我與外部程序發送命令。
我嘗試過使用Pyro4,但我似乎無法獲得服務器上運行的線程,然後使用客戶端進行控制。
任何想法?
您正在尋找流行語「Interprocess Communications」。研究它是如何在C中完成的,因爲這是python的大部分內容所基於的。在其他選項中,您可以使用套接字,管道,共享內存或可能(如果您想發送的內容有限的話)執行此操作,即信號處理程序。 –
使用Pyro4獲得「在服務器上運行」的問題是什麼?一旦啓動Pyro4守護進程的請求回調,它就會運行一個服務器進程來處理工作線程中的請求。 –