0
クラスにはさまざまな機能があります。別のクラスの別のファイルでは、メッセージをキャッチしてguiに印刷したいと思います。私は次のコードを持っているシミュレーションとして :私が欲しいもの2つの機能を別々のクラスに同期させる
import threading
import time
import logging
logging.basicConfig(level=logging.DEBUG, format='(%(threadName)-9s) %(message)s',)
message = None
def messages_generator(condition):
global message
with condition:
logging.debug('Condition: {}'.format(condition))
for i in range(5):
message = 'i = ' + str(i)
time.sleep(1)
logging.debug('Condition wait')
condition.wait()
def messages_sow(condition):
global message
with condition:
print(message)
logging.debug('Condition notify')
condition.notify()
logging.debug('Tread finished')
condition = threading.Condition()
messages_generator_thread = threading.Thread(name='Message Generator', target=messages_generator, args=(condition,))
messages_sow_thread = threading.Thread(name='Message Sow', target=messages_sow, args=(condition,))
messages_generator_thread.start()
messages_sow_thread.start()
はmessages_sow
強調テキストで印刷するメッセージを待機し、それが完了するまで継続するmessages_generator
です。上記のコードを実行すると、プログラムは2番目の '条件待ち'でフリーズします。 歓迎すべきアドバイス。