【发布时间】:2011-01-12 19:54:31
【问题描述】:
我需要在 ipython 中以一种允许继续交互的方式启动一个 twisted'reactor。 Ipython 的手册页引用了 twisted,但我无法理解我应该如何进行。文档引用了 IPython.kernel.twistedutil 所以我的印象是它应该是一个标准的解决方案......提前致谢
桑德罗 *:-)
【问题讨论】:
我需要在 ipython 中以一种允许继续交互的方式启动一个 twisted'reactor。 Ipython 的手册页引用了 twisted,但我无法理解我应该如何进行。文档引用了 IPython.kernel.twistedutil 所以我的印象是它应该是一个标准的解决方案......提前致谢
桑德罗 *:-)
【问题讨论】:
这是你的意思吗?
http://code.activestate.com/recipes/410670-integrating-twisted-reactor-with-ipython/
这将在 IPython 主线程旁边的一个线程中启动 Twisted reactor。您应该能够从 IPython 访问 Twisted 线程。
另一种可能的解决方案是在 .tac 文件中的 Twisted 应用程序旁边启动一个检修孔 "Service"。
【讨论】:
import thread
from twisted.internet import reactor, defer
# This usualy raises Unhandled Error
# exceptions.ValueError: signal only works in main thread
thread.start_new(reactor.run, ())
@defer.inlineCallbacks
def check():
print "It works!"
yield
reactor.callFromThread(check)
【讨论】: