How to start twisted's reactor from ipython

倖福魔咒の 提交于 2020-01-06 07:07:31

问题


I need to start a twisted'reactor 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 *:-)


回答1:


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.




回答2:


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)


来源:https://stackoverflow.com/questions/4673375/how-to-start-twisteds-reactor-from-ipython

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!