Eric Firing wrote: > In general, I don't think mpl is threadsafe at all; it uses global > variables, such as all the rc parameters, that could easily be > modified by one thread while being used by another. I think that > great care would be needed if one wanted to have multiple threads > making plots. Having one plotting thread and any number of threads > doing other things, however, should be OK. Oh yes -- I didn't think of the rcParams. > > Michael Droettboom wrote: >> At least the Agg backend *looks* to be reasonably threadsafe -- there >> are no obvious gotchas like global variables etc. Note, though, that >> multithreading may not gain much in the way of performance since the >> global interpreter lock is never released around long-running C blocks. > > Possibly this could be changed. The danger would be accidentally > modifying or deleting an array that is being used by C extension code. Modifying may be problematic, but deleting would not be likely -- the C function holds a reference to each of the arrays as they are using them. > >> >> However, I can't speak about this from any experience -- so, maybe it >> needs some trying. Any patches to help with thread safety and >> performance are of course welcome ;) > > At the very least, I think we would have to take all the global state > information and put it in a class instance, so there could be multiple > plotting machines. Pyplot would then instantiate and use one of > these; the OO API would allow one to instantiate any number of them. > I have not thought about how easy or hard this would be. Ditto that. Having just come back from PyCon, I'll parrot the standard Python answer to this question which is: "Don't use threads, use multiple processes", which would seem to solve all these issues -- but, I understand that it not always the best solution.
Mike > > Eric > >> >> Cheers, >> Mike >> >> Chris Withers wrote: >>> Hi All, >>> >>> I'm wondering what work people have done with matplotlib in >>> multi-threaded environments such as your average python web framework. >>> >>> Is matplotlib threadsafe? >>> >>> How have people gone about safely using it in a multi-threaded >>> environment? >>> >>> cheers, >>> >>> Chris >>> >>> >> >> >> ------------------------------------------------------------------------- >> >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio 2008. >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >> _______________________________________________ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users