【问题标题】:How to start twisted's reactor from ipython如何从 ipython 启动扭曲的反应器
【发布时间】:2011-01-12 19:54:31
【问题描述】:

我需要在 ipython 中以一种允许继续交互的方式启动一个 twisted'reactor。 Ipython 的手册页引用了 twisted,但我无法理解我应该如何进行。文档引用了 IPython.kernel.twistedutil 所以我的印象是它应该是一个标准的解决方案......提前致谢

桑德罗 *:-)

【问题讨论】:

    标签: twisted ipython


    【解决方案1】:

    这是你的意思吗?

    http://code.activestate.com/recipes/410670-integrating-twisted-reactor-with-ipython/

    这将在 IPython 主线程旁边的一个线程中启动 Twisted reactor。您应该能够从 IPython 访问 Twisted 线程。

    另一种可能的解决方案是在 .tac 文件中的 Twisted 应用程序旁边启动一个检修孔 "Service"

    【讨论】:

      【解决方案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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-01-16
        • 2015-05-04
        • 2018-03-02
        • 2011-08-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多