#31968·matplotlib

[Bug]: macosx backend crashes when used on a worker thread

Author: iccirCreated Jun 29, 2026Updated Sep 14, 2026
LabelsGUI: MacOSX

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

python
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