Closed
Description
Bug report
Bug summary
Matplotlib segfaults when creating a figure when used in combination with the standard multiprocessing library.
Code for reproduction
import multiprocessing as mp
import matplotlib.pyplot as plt
def plot():
fig = plt.figure()
def main(nprocs=2):
worker = mp.Process(target=plot)
worker.start()
worker.join()
if worker.exitcode < 0:
print("Error: %s exited with error code %i." % (worker.__str__(), worker.exitcode))
if __name__ == "__main__":
main()
Actual outcome
All processes exit with code -11, SYSSEGV
Expected outcome
I've figured out that creating a figure like this isn't expected to work with the GUI backend on. Putting:
import matplotlib
matplotlib.use('agg')
before the other imports fixes the issue. It's understandable that you can't create multiple instances of the GUI on different processes, however it seems to me an exception should be thrown rather than a segfault.
Matplotlib version
- Operating System: macOS 10.12.5
- Matplotlib Version: 2.0.2
- Python Version: 2.7.13, 3.6.1
- Other Libraries: multiprocessing
Matplotlib was installed from Conda, on the conda-forge
stream.