Title: Abort in free-threaded build due to mutation of `ChainMap` of a `Counter` in threads · Issue #126366 · python/cpython · GitHub
Open Graph Title: Abort in free-threaded build due to mutation of `ChainMap` of a `Counter` in threads · Issue #126366 · python/cpython
X Title: Abort in free-threaded build due to mutation of `ChainMap` of a `Counter` in threads · Issue #126366 · python/cpython
Description: What happened? The code below, in a no-gil debug build with PYTHON_GIL=0, results in the following abort: python: ./Include/internal/pycore_stackref.h:99: _PyStackRef_FromPyObjectSteal: Assertion `obj != NULL' failed. Aborted from thread...
Open Graph Description: What happened? The code below, in a no-gil debug build with PYTHON_GIL=0, results in the following abort: python: ./Include/internal/pycore_stackref.h:99: _PyStackRef_FromPyObjectSteal: Assertion `...
X Description: What happened? The code below, in a no-gil debug build with PYTHON_GIL=0, results in the following abort: python: ./Include/internal/pycore_stackref.h:99: _PyStackRef_FromPyObjectSteal: Assertion `...
Opengraph URL: https://github.com/python/cpython/issues/126366
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Abort in free-threaded build due to mutation of `ChainMap` of a `Counter` in threads","articleBody":"### What happened?\r\n\r\nThe code below, in a no-gil debug build with `PYTHON_GIL=0`, results in the following abort:\r\n```\r\npython: ./Include/internal/pycore_stackref.h:99: _PyStackRef_FromPyObjectSteal: Assertion `obj != NULL' failed.\r\nAborted\r\n```\r\n\r\n```python\r\nfrom threading import Thread\r\nfrom collections import ChainMap, Counter\r\n\r\ncounter = Counter(range(100))\r\nchainmap = ChainMap(counter)\r\nchainmap2 = ChainMap(counter)\r\n\r\ndef mutate_removing():\r\n for x in range(10):\r\n chainmap.pop(list(chainmap.keys()).pop())\r\n chainmap2.pop(list(chainmap2.keys()).pop())\r\n\r\ndef mutate_adding():\r\n for x in range(50):\r\n chainmap[max(chainmap) + x + 1] = x\r\n chainmap2[max(chainmap2) + x + 1] = x\r\n\r\nalive = []\r\n\r\nfor x in range(55):\r\n alive.append(Thread(target=mutate_removing, args=()))\r\n alive.append(Thread(target=mutate_adding, args=()))\r\n\r\nfor obj in alive:\r\n try:\r\n print('START', obj)\r\n obj.start()\r\n except Exception:\r\n pass\r\n```\r\n\r\nFound using fusil by @vstinner.\r\n\r\n\r\n### CPython versions tested on:\r\n\r\nCPython main branch\r\n\r\n### Operating systems tested on:\r\n\r\nLinux\r\n\r\n### Output from running 'python -VV' on the command line:\r\n\r\nPython 3.14.0a1+ experimental free-threading build (heads/main:556dc9b8a7, Nov 3 2024, 10:09:47) [GCC 11.4.0]\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-126369\n* gh-126371\n* gh-132693\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/devdanzin","@type":"Person","name":"devdanzin"},"datePublished":"2024-11-03T15:28:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/126366/cpython/issues/126366"}
| 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:17e36823-b861-33ea-6f2e-f09c9d034f20 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D69C:2C813C:33F6CEA:4A69661:6A5687CD |
| html-safe-nonce | f08a90896bb99f8ae6d2f3cf6b7f8ab74b21e600dc033f603fbe498c54a86367 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjlDOjJDODEzQzozM0Y2Q0VBOjRBNjk2NjE6NkE1Njg3Q0QiLCJ2aXNpdG9yX2lkIjoiNjg4NzAyNDExMDEwNDY0MzUzMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d0a8f9695495dd55a3d92d70a102a10f92bc988b5a52cd9f8b71a83155e1cbf1 |
| hovercard-subject-tag | issue:2631276004 |
| 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/126366/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f057ceaeb5c65d186cc686dd1ff14be6934fc99fb0e1675a734ccd4151c577ad/python/cpython/issues/126366 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f057ceaeb5c65d186cc686dd1ff14be6934fc99fb0e1675a734ccd4151c577ad/python/cpython/issues/126366 |
| og:image:alt | What happened? The code below, in a no-gil debug build with PYTHON_GIL=0, results in the following abort: python: ./Include/internal/pycore_stackref.h:99: _PyStackRef_FromPyObjectSteal: Assertion `... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | devdanzin |
| hostname | github.com |
| expected-hostname | github.com |
| None | 8f21be8503ba8fe6154df415b855c03af52eae3f285bd6ae1fef041dc053da38 |
| 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 | 78af172a48a2056810bb627ffa684003e4f9a5ca |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width