[IPython-dev] ipython with twisted reactor

tcb thecolourblue+m at gmail.com
Fri Mar 1 11:37:43 EST 2013


Hi,

I am trying to use the ipython notebook with some example code which sets
up a websocket server (using autobahn python
http://autobahn.ws/python/tutorials/echo ).

The problem is that I need to call twisted's reactor.run() method, but this
blocks all input, and I need to interact with the objects to send/receive
messages. I haven't been able to get this to work in the notebook yet. I
assume its a problem interacting with the tornado eventloop in ipython- but
it could be something else (the examples work fine outside of ipython).

Rather than calling reactor.run()- I've tried putting it into a thread:

threading.Thread(target=reactor.run,
kwargs={'installSignalHandlers':False}).start()


but that doesn't work either- it doesn't ever run.

The threadedselector doesn't seem to run either (putting this at the top of
my script):

from twisted.internet import _threadedselect
reactor = _threadedselect.install()


There is a possibility to interleave the twisted eventloop with other event
loops:

from twisted.internet import reactor

reactor.interleave(foreignEventLoopWakerFunction)


but I have no idea which ipython function would serve as a 'waker' function.

Has anyone managed to do this already in the notebook?

-thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20130301/dd17e215/attachment.html>


More information about the IPython-dev mailing list