Running twisted reactor in iPython
<p>I'm aware this is normally done with twistd, but I'm wanting to use iPython to test out code 'live' on twisted code.</p>

<p><a href="http://stackoverflow.com/questions/4673375/how-to-start-twisteds-reactor-from-ipython">How to start twisted&#39;s reactor from ipython</a> asked basically the same thing but the first solution no longer works with current ipython/twisted, while the second is also unusable (thread raises multiple errors).</p>

<p><a href="https://gist.github.com/kived/8721434" rel="nofollow">https://gist.github.com/kived/8721434</a> has something called TPython which purports to do this, but running that seems to work except clients never connect to the server (while running the same clients works in the python shell).</p>

<p>Do I <em>have</em> to use Conch Manhole, or is there a way to get iPython to play nice (probably with _threadedselect).</p>

<p>For reference, I'm asking using ipython 5.0.0, python 2.7.12, twisted 16.4.1</p>

<p>While this doesn't answer the question I thought I had, it does answer (sort of) the question I posted. Embedding ipython works in the sense that you get access to business objects with the reactor running.</p>

<pre><code>from twisted.internet import reactor
from twisted.internet.endpoints import serverFromString
from myfactory import MyFactory

class MyClass(object):
    def __init__(self, **kwargs):
        super(MyClass, self).__init__(**kwargs)
        server = serverFromString(reactor, 'tcp:12345')
        server.list(MyFactory(self))
        def interact():
            import IPython
            IPython.embed()
        reactor.callInThread(interact)

if __name__ == "__main__":
    myclass = MyClass()
    reactor.run()
</code></pre>

<p>Call the above with <code>python myclass.py</code> or similar.</p>

python ipython twisted