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

未關閉
#31,968 7 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
48/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
macos, python
領域
backend, desktop

研究方向

先使用 macosx backend 執行提供的 Python 重現程式,並比較列出的 worker-thread 方法。追蹤涉及的 macosx backend 入口點,接著讓已同意的背景執行緒呼叫引發 Python 錯誤,而不是造成當機,同時確認對 Timer 和 FigureCanvas.draw_idle() 的處理。

由索引模型根據 Issue 內容生成。

描述

GUI: 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
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

主要語言
Python
星號
23.6k
分支
8.6k
平均合併
1 天 19 小時
30 天內合併 PR
64

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

matplotlib/matplotlib 的其他 Issue

查看 matplotlib/matplotlib 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。