Cannot plot anything or display pylab frame in new process using python multiprocessing
Question: Does anyone have any idea why the code below won't even open up a pylab figure
window? If the body of the test function is moved to the main process it works
fine, but I'd like to do some plotting from within a new process specifically.

    
    
    from multiprocessing import Process
    from pylab import *
    
    def test():
        frac = [10, 10, 10, 10, 10, 10, 40]
        labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
        ion()
        hold(False)
        while True:
            pie(frac, labels = labels, autopct='%1.1f%%')
            title('test', bbox={'facecolor' : '0.8', 'pad' : 5})
            draw()
    
    
    p1 = Process(target = test)
    p1.daemon = True
    p1.start()
    
    while True:
        pass
    


Answer: Move all the GUI statements -- including the import statement -- into `test`:

    
    
    import multiprocessing as mp
    
    def test():
        import matplotlib.pyplot as plt
        frac = [10, 10, 10, 10, 10, 10, 40]
        labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
        plt.pie(frac, labels = labels, autopct='%1.1f%%')
        plt.title('test', bbox={'facecolor' : '0.8', 'pad' : 5})
        plt.show()    
    
    p1 = mp.Process(target = test)
    p1.daemon = True
    p1.start()
    p1.join()
    

Use `p1.join()` instead of `while True: pass`. It is much less CPU-intensive.

Finally, be sure to read the [Matplotlib animation
cookbook](http://www.scipy.org/Cookbook/Matplotlib/Animations) for examples on
how to do animation right.

