【发布时间】:2015-10-28 17:33:42
【问题描述】:
我在我的应用程序中使用了 twisted 并在它自己的线程中运行它。像这样使用 twisted 效果很好,但它永远不会正确停止。
例子:
# Python 2.7.6
# Twisted==15.4.0
import time
import threading
from twisted.internet import reactor
print("starting reactor")
reactor_thread = threading.Thread(target=reactor.run,
kwargs={"installSignalHandlers": False})
reactor_thread.start()
print("reactor started")
time.sleep(1)
print("stopping reactor")
reactor.stop()
print("joining thread")
reactor_thread.join()
print("reactor stopped") # <- never reached
输出:
starting reactor
reactor started
stopping reactor
joining thread
【问题讨论】:
标签: python multithreading twisted