Multiprocessing and matplotlib

Can matplotlib be used in scripts with multiple processes, such as
when using the multiprocessing module?

I had some difficulty getting code to work in which I was carrying out
some long computations and wanted to show intermediate results in a
separate process so as not to interrupt the main computation. The
problem distilled down to trying to use the multiprocessing module and
matplotlib together. This is a code snippet which I expected to work,
but doesn't. Is this a matplotlib issue, some intricate issue with
GUIs and processes, or something with my understanding of the subject?

Would you expect this code to work? Is there any easy workaround?

from pylab import *
import multiprocessing
class myclass(object):
    def plotter(self):
        plot([1,2,3,4])
        show()
    def mainfunction(self):
        a = arange(1, 10, 0.1)
        newprocess = multiprocessing.Process(target=self.plotter)
        newprocess.start()
        newprocess.join()
        plot(a, sin(a))
        show()
if __name__== '__main__':
    a = myclass()
    a.mainfunction()

Thanks,
Sameer

It's a backend issue:the code works with wxagg but not with gtkagg.

···

On 1 November 2010 00:54, Sameer Grover <sameer.grover.1@...287...> wrote:

Can matplotlib be used in scripts with multiple processes, such as
when using the multiprocessing module?

I had some difficulty getting code to work in which I was carrying out
some long computations and wanted to show intermediate results in a
separate process so as not to interrupt the main computation. The
problem distilled down to trying to use the multiprocessing module and
matplotlib together. This is a code snippet which I expected to work,
but doesn't. Is this a matplotlib issue, some intricate issue with
GUIs and processes, or something with my understanding of the subject?

Would you expect this code to work? Is there any easy workaround?

from pylab import *
import multiprocessing
class myclass(object):
def plotter(self):
plot([1,2,3,4])
show()
def mainfunction(self):
a = arange(1, 10, 0.1)
newprocess = multiprocessing.Process(target=self.plotter)
newprocess.start()
newprocess.join()
plot(a, sin(a))
show()
if __name__== '__main__':
a = myclass()
a.mainfunction()

Thanks,
Sameer