[IPython-dev] Twisted reactor + IPython0

Glenn H Tarbox, PhD glenn at tarbox.org
Wed Mar 19 18:51:34 EDT 2008


to wit:

import sys

from PyQt4 import QtGui
import qt4reactor

"""
this nails up the reactor and makes app available
at the module level
"""
app = QtGui.QApplication(sys.argv)
qt4reactor.install()

# alternative for those who don't need a gui
# from twisted.application import reactors
# reactors.installReactor('qt4')

from twisted.internet import reactor

reactor.runReturn()

# now you have the thread back, a live Qt application object, and 
# twisted... and you've got the IPython0 prompt back... then try

def callMe():
  print "he called me"
reactor.callLater(5,0,callMe)

you'll have the prompt back and 5 seconds later it'll print


On Wed, 2008-03-19 at 15:35 -0700, Glenn H Tarbox, PhD wrote:
> This is where I started originally.  There's a better fix which I posted
> a while ago.  The below uses polling which is unnecessary.  By modifying
> shell, you can turn the whole thing into a callback.
> 
> A better approach is to use my qtreactor (it sucks in qt but) because
> you can instantiate twisted (and qt) and keep the event loop for
> stdin/stdout and have reactor behavior as well.
> 
> the key with qtreactor is I made a new call = reactor.runReturn() which
> nails up the reactor to the Qt application, sets up the timers etc, but
> returns the thread to you... so as long as I/O in IPython doesn't block
> (which it only does when scrolling more than a page)
> 
> -glenn
> 
> 
> On Wed, 2008-03-19 at 23:39 +0200, Ville M. Vainio wrote:
> > This is related to the recent thread about reactors, GUI support etc.
> > 
> > Would it make sense to provide direct twisted reactor support for ipython0?
> > 
> > There is a recipe for this:
> > 
> > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410670
> > 
> > If this works as expected, can't we just implement all the GUI support
> > widgets in terms of this baby, using the support bundled with twisted?
> > 
> > A couple of you have gathered extensive experience with Twisted, what
> > do you think?
> > 
-- 
Glenn H. Tarbox, PhD
206-494-0819
glenn at tarbox.org




More information about the IPython-dev mailing list