From: Fernando P. <Fer...@co...> - 2005-01-28 00:14:57
|
Steve Chaplin wrote: > On Tue, 2005-01-25 at 22:25 -0700, Fernando Perez wrote: > >>In case anyone is interested, here's a lightweight, standalone (non-ipython) >>GTK threaded interactive interpreter with matplotlib support. This code is >>also based on the same ASPN recipe, it's basically the prototype I used to >>understand that recipe when I was adding the matplotlib support to IPython. > > Thanks, its a good example of code.InteractiveConsole, when I saw codeop in > the ASPN recipe I wondered why code.py was not used. > > I noticed a few small points: > - GTKInterpreter says "Run a gtk mainloop() in a separate thread.", yet > gtk.main() runs in the main thread, and the interpreter/console runs in > a separate thread. You are correct. > - gtk.timeout_add() is now deprecated in favour of gobject.timeout_add() Feel free to fix it, I didn't know better. > - runsource() and runcode() are synchronised using wait()/notify() so > they deal with one code object at a time. If self.code_to_run is changed > to a code queue (using list.append() and list.pop(0)) then the wait > ()/notify() could be removed and the interpreter thread would return > immediately it adds the code to self.code_to_run and not when the main > thread has executed the code. On second thought, I don't think this is a good idea in general. The problem I see is the serialization of output. Imagine you start a long running job and you get the prompt back right away. If your job prints to stdout along the way (as is very common with scientific codes), your input line will get clobbered by this output. If you could run in a gui window where you could associate the stdout for each input 'cell' with its own output one, it would be different. This is exactly how Mathematica notebooks work, they stack a queue of cells for running sequentially, you get your typing prompt back immediately, but the output of each command is collected in an Out[] cell next to the corresponding In[] one. In a plain terminal, I don't see how we can make this work (in fact, in a terminal Mathematica also serializes output for this very reason). I have been toying with the idea of adding a way to 'background' processes automatically to ipython, by creating a list of worker threads for long running jobs. But the problem of handling stdout has me stumped. I'm open to comments, though, or perhaps I'm missing something obvious here. Best, f |