0
私は、異なるモジュールのメソッドを実行している別のスレッドに渡すブール値を持っています。このブール値は取り消しトークンとして機能するので、スレッドが終了する必要があります。私は別のスレッドでそれを設定すると、他のスレッドでは変更されないので、値渡しと思われます。ありがとう。スレッドとモジュール間の参照でブール値を渡す方法
import module2
from threading import Thread
cancellationToken = False
def main:
thread2 = Thread(target = module2.method2, args (on_input, cancellationToken,))
thread2.start()
...
thread2.join()
def on_input(command):
global cancellationToken
...
if(...):
cancellationToken = True
...
module2のmethod2は、キャンセルトークンをチェックしてユーザーの入力に応答する単純な無限ループです。
def method2(on_input, cancellationToken):
while(True):
if(cancellationToken):
return
...
on_input(...)
シンプルなブールの場合は、 'Event'オブジェクトを使うことができます:https://docs.python.org/3.4/library/threading.html#event-objects –