Python: provide some data (matplotlib) without GIL

My problem is of course the GIL. While I'm parsing the data, it would be nice to present some graphs in between (so it's not too boring while waiting for the results)

But the GIL prevents this (and this leads me to ask myself if Python was really such a good idea).

I can only display the plot, wait for the user to close it and start calculating after that. Obviously a waste of time.

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

Any thoughts on this? Thanks to

Edit: Ok, so this is not the GIL but show ().

+2


a source to share


4 answers


This is not a problem with matplotlib or the GIL.

In matplotlib, you can open up as many numbers as you want and have them on screen while your application continues to do other things.

You have to use matplotlib interactively. This is probably your problem.



from matplotlib import interactive
interactive(True)

      

this should be at the top of your import

+5


a source


This has nothing to do with the GIL, just change your parsing code to update the graph from time to time (e.g. every N iterations).



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

+3


a source


I think you will need to put the timeline in the correct Windowing system and not rely on the built-in showcode.

Could .show () be missing on a different thread?

The GIL doesn't matter - you have a blocking show () call, so you need to handle it first.

+3


a source


It looks like the draw () method can get around the need for show ().

The only reason for .show () in a script is to allow it to block the part so that the images don't fade out when the script reaches its end.

+2


a source







All Articles