[IPython-dev] Macros don't work in threaded shells

Ville M. Vainio vivainio at gmail.com
Mon Mar 10 14:53:08 EDT 2008

It appears recursive execution of _ip.runlines() is not possible with
threaded shells (and so e.g. macros hang ipython) - noticed this
through ticket #238, which is now a blocker.


ipython -q4thread

> _ip.runlines('1')

This will hang IPython.

First, we come to MTInteractiveShell.runsource(""" _ip.runlines('1')""")

This is given to runcode, which then does runsource( "1"). This never
gets to runcode, because the thread is waiting for  _ip.runlines('1')
to complete.

According to this comment, it seems this scenario has been considered,
but the logic does not seem to work:

       # Case 3
        # Store code in queue, so the execution thread can handle it.

        # Note that with macros and other applications, we MAY re-enter this
        # section, so we have to acquire the lock with non-blocking semantics,
        # else we deadlock.
        got_lock = self.thread_ready.acquire()
        if got_lock:
           self.thread_ready.wait()  # Wait until processed in timeout interval
            print "nolock",source

(and no, using got_lock = self.thread_ready.acquire(blocking=False)
won't fix it).

Fernando? You remember whether this used to work?

Ville M. Vainio - vivainio.googlepages.com
blog=360.yahoo.com/villevainio - g[mail | talk]='vivainio'

More information about the IPython-dev mailing list