編輯:我遇到的問題與我的程序結構無關。 FAPWS3的路由選擇了一個類似的,密切相關的功能。Python全局threading.condition()和在多個模塊中使用
我有一個大型程序分佈在多個文件。我需要在這些文件中使用threading.condition()鎖定功能。這是我想要做的一個例子。在生產中,我沒有得到任何錯誤,但鎖的狀態似乎沒有共享(我可以在一個線程中獲取,並且在另一個線程中獲取而沒有先前被釋放)。
main.py
import servera, serverb
# some code that deploys server-a and server-b as threads
constants.py
import threading
mylock = threading.Condition()
servera.py
from constants import mylock
Class ServerA():
def doSomething():
mylock.acquire()
# do something
mylock.release()
serverb.py
from constants import mylock
Class ServerB():
def doSomethingElse():
mylock.acquire()
# do something else
mylock.release()
你的意見並不能真正解釋你爲什麼會遇到問題;請發佈一個實際演示問題的最小工作代碼示例。 – SingleNegationElimination