views:

202

answers:

4

Hello all,

my problem is the GIL of course. While I'm analysing data it would be nice to present some plots in between (so it's not too boring waiting for results)

But the GIL prevents this (and this is bringing me to the point of asking myself if Python was such a good idea in the first place).

I can only display the plot, wait till the user closes it and commence calculations after that. A waste of time obviously.

I already tried the subprocess and multiprocessing modules but can't seem to get them to work.

Any thoughts on this one? Thanks

Edit: Ok so it's not the GIL but show().

+3  A: 

This has nothing to do with the GIL, just modify your analysis code to make it update the graph from time to time (for example every N iterations).

Only then if you see that drawing the graph slows the analysis code too much, put the graph update code in a subprocess with multiprocessing.

Luper Rouch
I don't think you understood what I mean. When the plot displays, the interpreter stops until the window is closed. Put a print statement before and after a show() and you'll see...Or if I'm wrong could you include some pseudo codde to illustrate the correct use of the plotting commands (specifically where to put the show() method call?
BandGap
[show()](http://matplotlib.sourceforge.net/faq/howto_faq.html#use-show), as the doc says, is supposed to be used only once in your script. You'll need to use another method for what you want to do. For example you could render your graph to an image and display it with an external program, like eog, or if you use a GUI render to a pixmap, etc...
Luper Rouch
+3  A: 

I think you'll need to put the graph into a proper Windowing system, rather than relying on the built-in show code.

Maybe sticking the .show() in another thread would be sufficient?

The GIL is irrelevant - you've got a blocking show() call, so you need to handle that first.

Douglas Leeder
+5  A: 

This is not a problem from matplotlib or the GIL.

In matplotlib You can open as many figures as you want and have them in the screen while your application continues doing other things.

You must use matplotlib in interactive mode. This probably is your problem.

from matplotlib import interactive
interactive(True)

this should be at the top of your imports

joaquin
+2  A: 

It seems like the draw() method can circumvent the need for show().

The only reason left for .show() in the script is to let it do the blocking part so that the images don't disapear when the script reaches its end.

BandGap
+1: I was wondering when someone would mention this… :)
EOL