def threaded_reactor():
"""
Start the Twisted reactor in a separate thread, if not already done.
Returns the reactor.
"""
global _twisted_thread
if not _twisted_thread:
from threading import Thread
_twisted_thread = Thread(target=lambda: reactor.run(installSignalHandlers=False), name="Twisted")
_twisted_thread.setDaemon(True)
_twisted_thread.start()
def hook_observer():
observer = log.PythonLoggingObserver()
observer.start()
import logging
log.msg("PythonLoggingObserver hooked up", logLevel=logging.DEBUG)
reactor.callFromThread(hook_observer)
return reactor, _twisted_thread
评论列表
文章目录