Title: [Bug]: macosx backend crashes when used on a worker thread · Issue #31968 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: macosx backend crashes when used on a worker thread · Issue #31968 · matplotlib/matplotlib
X Title: [Bug]: macosx backend crashes when used on a worker thread · Issue #31968 · matplotlib/matplotlib
Description: 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...
Open Graph Description: 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 vario...
X Description: 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 ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31968
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: macosx backend crashes when used on a worker thread","articleBody":"### Bug summary\n\nWhile [Interactive figures and asynchronous programming](https://matplotlib.org/3.6.3/users/explain/interactive_guide.html#threading) 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:\n\n| Method | Result |\n|-|-|\nFigureCanvas.flush_events | CRASH\nFigureManager.set_window_title | Obj-C Exception\nFigureManager.show | CRASH\nFigureManager.resize | CRASH\nFigureManager.full_screen_toggle | CRASH\n\nSome 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](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html), so our usage falls into a gray area.\n\nI 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?\n\n### Code for reproduction\n\n```Python\nimport threading\nimport matplotlib\nimport matplotlib.pyplot as plt\n\nmatplotlib.use(\"macosx\")\n \nfig = plt.figure()\ncanvas = fig.canvas\nmanager = fig.canvas.manager\n\ndef worker():\n canvas.flush_events() # EXC_BAD_ACCESS (SIGSEGV)\n# manager.show()\n# manager.resize(100, 200)\n \nt = threading.Thread(target=worker)\nt.start()\nt.join()\n```\n\n### Actual outcome\n\nSIGSEGV, SIGTRAP, Obj-C Exception\n\n### Expected outcome\n\nA Python error is thrown.\n\n### Additional information\n\n_No response_\n\n### Operating system\n\n_No response_\n\n### Matplotlib Version\n\n3.11\n\n### Matplotlib Backend\n\nmacosx\n\n### Python version\n\n3.14.5\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nNone","author":{"url":"https://github.com/iccir","@type":"Person","name":"iccir"},"datePublished":"2026-06-29T16:14:29Z","url":"https://github.com/matplotlib/matplotlib/issues/31968"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d27b0a02-7e11-71d6-7861-97b9e0042323 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BE94:32CBBB:110E3B8:16AD743:6B06553F |
| html-safe-nonce | a7552a82619cedfc6d9c66c5656b15e9388d6a1699b72e1cc1288d40882794eb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRTk0OjMyQ0JCQjoxMTBFM0I4OjE2QUQ3NDM6NkIwNjU1M0YiLCJ2aXNpdG9yX2lkIjoiMTA4NzQ3ODM1OTU2ODgzMTgwNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b2922cbf928b406a7d56649d479bcdc36c66b5b01fc9f7012cf44903f0ca4bf7 |
| hovercard-subject-tag | issue:4769775803 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/31968/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5caf8292fd0cae9bf1f46c6684a26fd07d62adb0e6e6dc79f2048df729394839/matplotlib/matplotlib/issues/31968 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5caf8292fd0cae9bf1f46c6684a26fd07d62adb0e6e6dc79f2048df729394839/matplotlib/matplotlib/issues/31968 |
| og:image:alt | 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 vario... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iccir |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6324e6ac990fb6befbec840cc0e102a1071c339bfe8f9826bb12de2e3ba1d297 |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7f0aa75f4141d440c6110dc31af7ea7797abb6c4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width