How to start twisted's reactor from ipython
I need to start a twisted'r开发者_JS百科eactor from within ipython in a way that allows to go on interacting. Ipython's man page has references to twisted but I couldn't understand the way I should proceed. Documentation references IPython.kernel.twistedutil so that my impression is that it should be a standard solution... Thanks in advance
sandro *:-)
Is this what you mean?
http://code.activestate.com/recipes/410670-integrating-twisted-reactor-with-ipython/
This will start the Twisted reactor in a thread alongside IPython's main thread. You should be able to access the Twisted thread from IPython.
Another possible solution would be to start a manhole "Service" alongside your Twisted application in a .tac
file.
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)
精彩评论