Title: [Bug]: Embedded Python uncatchable hard exit on closing last matplotlib window. · Issue #27147 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Embedded Python uncatchable hard exit on closing last matplotlib window. · Issue #27147 · matplotlib/matplotlib
X Title: [Bug]: Embedded Python uncatchable hard exit on closing last matplotlib window. · Issue #27147 · matplotlib/matplotlib
Description: Bug summary On macOS, default backend (Cocoa?), with Python embedded into an application, closing the last open Matplotlib window causes an uncatchable exit. It does not throw a system exit exception to call Python's system exit, but rat...
Open Graph Description: Bug summary On macOS, default backend (Cocoa?), with Python embedded into an application, closing the last open Matplotlib window causes an uncatchable exit. It does not throw a system exit excepti...
X Description: Bug summary On macOS, default backend (Cocoa?), with Python embedded into an application, closing the last open Matplotlib window causes an uncatchable exit. It does not throw a system exit excepti...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/27147
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Embedded Python uncatchable hard exit on closing last matplotlib window.","articleBody":"### Bug summary\n\nOn macOS, default backend (Cocoa?), with Python embedded into an application, closing the last open Matplotlib window causes an uncatchable exit. It does not throw a system exit exception to call Python's system exit, but rather a C level exit which causes the entire application to close. This is fine if you are running Matplotlib from an interactive console, it is not fine when Python is embedded as a scripting language within an application. \n\n### Code for reproduction\n\n```python\n# Embed Python into a minimal application, run application \r\n# from the embedded python scripting, run the script.\r\n# Such as running through PyRun_SimpleString(\"code\"); (not an interactive shell)\r\n\r\nimport matplotlib.pyplot as plt\r\nplt.clf() # make sure we are starting with a clean plot\r\nplt.plot([1, 2, 3, 4])\r\nplt.ylabel('some numbers')\r\nplt.show()\r\n\r\n# close the window - application exits in an uncatchable manner.\n```\n\n\n### Actual outcome\n\nApplication shutdown that is not catchable.\n\n### Expected outcome\n\nWindow closes and script stops running and control is returned to interpreter, but Application with Python interpreter continues running. Backend returns to a state waiting for another plot / window to be opened.\n\n### Additional information\n\nUse Matplotlib from an application that embeds Python as a scripting language. Close last Matplotlib window. Matplotlib forces application to close ungracefully, no way to catch close, no way to save / close opened files no way for an orderly shutdown and a C level exit is called.\r\n\r\nMatplotlib always forces exit for every version tried.\r\nWhy: A call to exit() or exit_() at the C level of the code, not a Python SystemExit.\r\nFix: Don't terminate the application with an uncatchable exit.\n\n### Operating system\n\nmacOS\n\n### Matplotlib Version\n\n3.8.0 and prior\n\n### Matplotlib Backend\n\nMacOSX\n\n### Python version\n\n3.11.5 ( and earlier all the way back to 3.5)\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/prniii","@type":"Person","name":"prniii"},"datePublished":"2023-10-19T14:15:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/27147/matplotlib/issues/27147"}
| 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:51b15b1d-ba04-5223-666b-8c6939343c4a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8FCC:17598F:5487BA:70BF41:6A53EB26 |
| html-safe-nonce | e3f2f40465f661077fe66b3f73074f168cdaa45c72c97ac70f8e4f5faa8ab74d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RkNDOjE3NTk4Rjo1NDg3QkE6NzBCRjQxOjZBNTNFQjI2IiwidmlzaXRvcl9pZCI6Ijc2Nzk1Nzg5MDkxODEyMDkzODMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d4c90621d6e6c849cb0f6a73b8a43923de486c1e203b62063c10c300ac514fd8 |
| hovercard-subject-tag | issue:1952374330 |
| 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/27147/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f339e425b1ba4ee6c6c6903d3568a13d02d8dd6781db1e5cb4d27eb11c96bd21/matplotlib/matplotlib/issues/27147 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f339e425b1ba4ee6c6c6903d3568a13d02d8dd6781db1e5cb4d27eb11c96bd21/matplotlib/matplotlib/issues/27147 |
| og:image:alt | Bug summary On macOS, default backend (Cocoa?), with Python embedded into an application, closing the last open Matplotlib window causes an uncatchable exit. It does not throw a system exit excepti... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | prniii |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width