Bug summary
While Interactive figures and asynchronous programming specifically states that "In general Matplotlib is not thread safe", the macosx backend crashes with SIGSEGV or SIGTRAP when various methods are called on a worker thread:
| Method |
Result |
| FigureCanvas.flush_events |
CRASH |
| FigureManager.set_window_title |
Obj-C Exception |
| FigureManager.show |
CRASH |
| FigureManager.resize |
CRASH |
| FigureManager.full_screen_toggle |
CRASH |
Some methods, like FigureCanvas.set_cursor, do work without crashing; however, NSCursor isn't documented to be thread-safe. It's also not on the historic list of thread-unsafe classes, so our usage falls into a gray area.
I think we should default to setting a Python error when any macosx backend method is called on a background thread, with specific exceptions for Timer or FigureCanvas.draw_idle(). Possibly others?
Code for reproduction
import threading
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use("macosx")
fig = plt.figure()
canvas = fig.canvas
manager = fig.canvas.manager
def worker():
canvas.flush_events() # EXC_BAD_ACCESS (SIGSEGV)
# manager.show()
# manager.resize(100, 200)
t = threading.Thread(target=worker)
t.start()
t.join()
Actual outcome
SIGSEGV, SIGTRAP, Obj-C Exception
Expected outcome
A Python error is thrown.
Additional information
No response
Operating system
No response
Matplotlib Version
3.11
Matplotlib Backend
macosx
Python version
3.14.5
Jupyter version
No response
Installation
None
Bug summary
While Interactive figures and asynchronous programming specifically states that "In general Matplotlib is not thread safe", the macosx backend crashes with
SIGSEGVorSIGTRAPwhen various methods are called on a worker thread:Some methods, like
FigureCanvas.set_cursor, do work without crashing; however,NSCursorisn't documented to be thread-safe. It's also not on the historic list of thread-unsafe classes, so our usage falls into a gray area.I think we should default to setting a Python error when any macosx backend method is called on a background thread, with specific exceptions for
TimerorFigureCanvas.draw_idle(). Possibly others?Code for reproduction
Actual outcome
SIGSEGV, SIGTRAP, Obj-C Exception
Expected outcome
A Python error is thrown.
Additional information
No response
Operating system
No response
Matplotlib Version
3.11
Matplotlib Backend
macosx
Python version
3.14.5
Jupyter version
No response
Installation
None