문제

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().

도움이 되었습니까?

해결책

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

다른 팁

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.

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.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top