Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Plot some data (matplotlib) without GIL

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

like image 857
BandGap Avatar asked Jul 30 '26 06:07

BandGap


2 Answers

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

like image 105
joaquin Avatar answered Aug 01 '26 20:08

joaquin


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.

like image 25
Luper Rouch Avatar answered Aug 01 '26 19:08

Luper Rouch