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

Ville M. Vainio vivainio@gmail....
Mon Mar 10 13:53:08 CDT 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.

Try:

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()
        self.code_queue.put(code)
        if got_lock:
           self.thread_ready.wait()  # Wait until processed in timeout interval
        else:
            print "nolock",source
        self.thread_ready.release()

(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