3

I would like to draw figures on multiple cores in parallel with Matplotlib using the Agg backend without having to start multiple Python processes. This could be achieved with multithreading if Matplotlib released the global interpreter lock (GIL) while drawing figures.

I've tried searching the Matplotlib codebase for PyEval_SaveThread and Py_BEGIN_ALLOW_THREADS that are necessary to release the GIL. Based on this search it seems that Matplotlib only releases the GIL when resampling images. There are also no PyGILState_Ensure calls which would happen if new threads were created in an extension except in an OS X specific file. However, I don't really know the Matplotlib source and it is possible the GIL release happens in a dependency.

Agost Biro
  • 2,709
  • 1
  • 20
  • 33
  • If you do it right, there are usually no problems with multiple threads or processes. What about the inverse approach, try it out and if it fails look for the reason? – ImportanceOfBeingErnest Oct 11 '17 at 13:19
  • Here would be an example of using multiprocessing to save a lot of matplotlib figures on several cores: [matplotlib savefig performance, saving multiple pngs within loop](https://stackoverflow.com/questions/41037840/matplotlib-savefig-performance-saving-multiple-pngs-within-loop) – ImportanceOfBeingErnest Oct 11 '17 at 13:33

0 Answers0