Title: Initialize/Finalize Python multiple time and import datetime each time lead to a memory corruption · Issue #118608 · python/cpython · GitHub
Open Graph Title: Initialize/Finalize Python multiple time and import datetime each time lead to a memory corruption · Issue #118608 · python/cpython
X Title: Initialize/Finalize Python multiple time and import datetime each time lead to a memory corruption · Issue #118608 · python/cpython
Description: Crash report What happened? Example on Windows (debug build): # Taken from _ctypes issue: #116467 import subprocess program = r"PCbuild\amd64\_testembed_d.exe" cmd = [program, "test_repeated_init_exec", "import datetime"] # or _datetime ...
Open Graph Description: Crash report What happened? Example on Windows (debug build): # Taken from _ctypes issue: #116467 import subprocess program = r"PCbuild\amd64\_testembed_d.exe" cmd = [program, "test_repeated_init_e...
X Description: Crash report What happened? Example on Windows (debug build): # Taken from _ctypes issue: #116467 import subprocess program = r"PCbuild\amd64\_testembed_d.exe" cmd = [program, "test_...
Opengraph URL: https://github.com/python/cpython/issues/118608
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Initialize/Finalize Python multiple time and import datetime each time lead to a memory corruption","articleBody":"# Crash report\r\n\r\n### What happened?\r\n\r\nExample on Windows (debug build):\r\n\r\n```py\r\n# Taken from _ctypes issue: #116467\r\nimport subprocess\r\nprogram = r\"PCbuild\\amd64\\_testembed_d.exe\"\r\ncmd = [program, \"test_repeated_init_exec\", \"import datetime\"] # or _datetime\r\n\r\nfor i in range(1, 11):\r\n print(f\" == Process #{i} ===\")\r\n proc = subprocess.run(cmd)\r\n exitcode = proc.returncode\r\n print(f\"=\u003e exitcode {exitcode}\")\r\n if exitcode:\r\n break\r\n print()\r\n```\r\n\r\n\r\nOutput (7bbce383fa207ad83a6221bf70678c75c3c92142: CI failures with a similar test):\r\n```\r\nRunning Debug|x64 interpreter...\r\n == Process #1 ===\r\n--- Loop #1 ---\r\n--- Loop #2 ---\r\nAssertion failed: PyUnicode_CheckExact(ep_key), file C:\\a\\Objects\\dictobject.c, line 1119\r\n=\u003e exitcode 3\r\n```\r\n\r\n\r\nIt is an expected error on a debug build, which comes form [`_PyUnicode_ClearInterned()`](https://github.com/python/cpython/blob/ea2c0016502472aa8baa3149050ada776d17a009/Objects/unicodeobject.c#L14679) in `unicodeobject.c` of the commit ea2c001:\r\n\r\n```c\r\nvoid\r\n_PyUnicode_ClearInterned(PyInterpreterState *interp)\r\n{\r\n ...\r\n /* TODO:\r\n * Currently, the runtime is not able to guarantee that it can exit without\r\n * allocations that carry over to a future initialization of Python within\r\n * the same process. i.e:\r\n * ./python -X showrefcount -c 'import itertools'\r\n * [237 refs, 237 blocks]\r\n *\r\n * Therefore, this should remain disabled for until there is a strict guarantee\r\n * that no memory will be left after `Py_Finalize`.\r\n */\r\n#ifdef Py_DEBUG\r\n ...\r\n```\r\nCurrently, release builds avoid the `datetime` crash by leaking all interned strings. Both the crash and the leak should be fixed before shipping 3.13 final.\r\n\r\n\u003cbr\u003e\r\n\r\nThis dedicated issue is requested in:\r\n\r\n* #103092\r\n\r\n### CPython versions tested on:\r\n\r\n3.12, CPython main branch\r\n\r\n### Operating systems tested on:\r\n\r\nLinux, macOS, Windows\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-118531\r\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/neonene","@type":"Person","name":"neonene"},"datePublished":"2024-05-05T20:00:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/118608/cpython/issues/118608"}
| 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:846fe3fe-18ad-62ff-3790-c4c3704dad92 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9D16:9F1EC:1534A73:1DADEEA:696A420C |
| html-safe-nonce | c8ce724617c100d849f7ad86030ab2448fe5b028de64c8bc26ea3a1e580c9cc3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDE2OjlGMUVDOjE1MzRBNzM6MURBREVFQTo2OTZBNDIwQyIsInZpc2l0b3JfaWQiOiI1OTU3NDQ1ODc4NDQ2NDQwOTcyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2379f9eb30b7ccd29b35f6198748656f9b42e982660ff18b4e79c9e3a39cd1d1 |
| hovercard-subject-tag | issue:2279704546 |
| 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/python/cpython/118608/issue_layout |
| twitter:image | https://opengraph.githubassets.com/be04b64ede6bd7f0f9610349c21866df9e660f62f4b2358cf0fe758a78f965bf/python/cpython/issues/118608 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/be04b64ede6bd7f0f9610349c21866df9e660f62f4b2358cf0fe758a78f965bf/python/cpython/issues/118608 |
| og:image:alt | Crash report What happened? Example on Windows (debug build): # Taken from _ctypes issue: #116467 import subprocess program = r"PCbuild\amd64\_testembed_d.exe" cmd = [program, "test_repeated_init_e... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | neonene |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3f871c8e07f0ae1886fa8dac284166d28b09ad5bada6476fc10b674e489788ef |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| 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 | 63c426b30d262aba269ef14c40e3c817b384cd61 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width