python: twisted app with interacive python shell

故事扮演 提交于 2019-12-11 10:38:00

问题


Would it be possible to write a twisted-powered application that opens an interactive shell, e.g. to tweak the business objects served via the twisted protocol layer?

My current problem is that the reactor.run() blocks the application, and the IPython.embed() is only run after the reactor has finished.


回答1:


Unless you specifically need extras that are only in ipython, you really should check out manhole (twistedmatrix example code)

It lets you access a python interactive shell that is natively running in the twisted reactor. Normally the shell is accessed via telnet or ssh, but if you wanted to be creative you could wire it up any way you want.




回答2:


... Meanwhile I found an answer to my question: http://twistedmatrix.com/documents/current/core/howto/threading.html

def interact():
   import IPython
   IPython.embed()

reactor.callInThread(interact)
reactor.run()


来源:https://stackoverflow.com/questions/23633167/python-twisted-app-with-interacive-python-shell

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