5

I have a small script creating different plots. Since no data are shared, I can do some multiprocessing. Using python2.7, no problem. With python3.6, I can´t seem to make it work. I am using a pool (https://docs.python.org/3/library/multiprocessing.html and https://docs.python.org/2/library/multiprocessing.html) since I do not share objects or anything. For Python3, I get a crash without traceback at line (fig = plt.figure(number)). I am running on MacOs X sierra. I believe the problem is the same as for this topic (Saving multiple matplotlib figures with multiprocessing). Unfortunately, the problem wasn´t really addressed as not being the main issue.

One fast answer would be to use python2.7, but other pieces of my work rely on python3+ features. Any idea on how to have traceback at least (verbose mode didn't show anything related to the crash), and then to solve this issue?

Many thanks

Here is the smallest code producing the error, coming from the thread mentioned above. (this code will create 4 files in the folder of the script).

import matplotlib.pyplot as plt
import numpy.random as random
from multiprocessing import Pool


def do_plot(number):
    fig = plt.figure(number)
    a = random.sample(100)
    b = random.sample(100)

    plt.scatter(a, b)

    plt.savefig("%03d.jpg" % (number,))
    plt.close()

    print("Done ", number)


if __name__ == '__main__':
    pool = Pool()
    pool.map(do_plot, range(4))
Community
  • 1
  • 1
RysDe
  • 93
  • 8
  • I once answered [this question](http://stackoverflow.com/questions/41037840/matplotlib-savefig-performance-saving-multiple-pngs-within-loop) where I did not create multiple figures in multiprocessing. This was only tested with python 2, but you might want to try if it runs in python 3. It then might get you around the crash. – ImportanceOfBeingErnest Mar 09 '17 at 17:01
  • The main difference between your solution and my MnWE is that the plt.figure() is declared outside the main thread, not for each instance of the pool. As I mentioned, I am on MacOSX and this raises another problem: The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec(). Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug. http://stackoverflow.com/questions/16254191/python-rpy2-and-matplotlib-conflict-when-using-multiprocessing – RysDe Mar 09 '17 at 18:02

0 Answers0