Title: str.maketrans on a mutating dict is not thread-safe · Issue #145142 · python/cpython · GitHub
Open Graph Title: str.maketrans on a mutating dict is not thread-safe · Issue #145142 · python/cpython
X Title: str.maketrans on a mutating dict is not thread-safe · Issue #145142 · python/cpython
Description: Crash report What happened? A reproducer (in the format of Lib/tests/test_free_threading/xxx.py): import unittest from test.support import threading_helper threading_helper.requires_working_threading(module=True) class ItertoolsThreading...
Open Graph Description: Crash report What happened? A reproducer (in the format of Lib/tests/test_free_threading/xxx.py): import unittest from test.support import threading_helper threading_helper.requires_working_threadi...
X Description: Crash report What happened? A reproducer (in the format of Lib/tests/test_free_threading/xxx.py): import unittest from test.support import threading_helper threading_helper.requires_working_threadi...
Opengraph URL: https://github.com/python/cpython/issues/145142
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"str.maketrans on a mutating dict is not thread-safe","articleBody":"# Crash report\n\n### What happened?\n\nA reproducer (in the format of `Lib/tests/test_free_threading/xxx.py`):\n\n```python\nimport unittest\nfrom test.support import threading_helper\n\nthreading_helper.requires_working_threading(module=True)\n\n\nclass ItertoolsThreading(unittest.TestCase):\n\n @threading_helper.reap_threads\n def test_maketrans(self):\n number_of_iterations = 10\n number_of_attempts=100\n for _ in range(number_of_iterations):\n print(f'iteration {_}')\n d = {2000: 'a'}\n def work_iterator(dct):\n for idx in range(number_of_attempts):\n str.maketrans(dct)\n idx = 2000 + idx # outside range of small ints\n dct[idx] = chr(idx%16)\n dct.pop(idx, None)\n threading_helper.run_concurrently(work_iterator, nthreads=10, args=[d])\n\nif __name__ == \"__main__\":\n unittest.main()\n print('done')\n```\n\nAt first glance it seems that the iteration using `PyDict_Next` is not safe (but maybe there are more unsafe parts):\n\nhttps://github.com/python/cpython/blob/24cc998c164f137603f1c6d95b929d640211d237/Objects/unicodeobject.c#L13158\n\n\n(found when reviewing #145129)\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nWindows\n\n### Output from running 'python -VV' on the command line:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-145157\n* gh-145320\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/eendebakpt","@type":"Person","name":"eendebakpt"},"datePublished":"2026-02-23T14:33:24.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/145142/cpython/issues/145142"}
| 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:faf576e2-df5c-8952-1a68-278c40411ec9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BCDA:1FFDFF:67CE85B:9198D7D:6A5052C8 |
| html-safe-nonce | 7f0f222b70ddc836025fe85b37acc1fb6c95a835e5fbf55620130f66cb5fe1d5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0RBOjFGRkRGRjo2N0NFODVCOjkxOThEN0Q6NkE1MDUyQzgiLCJ2aXNpdG9yX2lkIjoiNDY0NjkwNDQ5MDA0NTIzMTgxNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e68368edbf6380a8f6863e984427c7102dda572f42919008bf8e5e47f7aa258a |
| hovercard-subject-tag | issue:3978491141 |
| 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/145142/issue_layout |
| twitter:image | https://opengraph.githubassets.com/92a6a181970077d6789fc754fcefdc4ea45bec5d8be712d7829d82e520c1d310/python/cpython/issues/145142 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/92a6a181970077d6789fc754fcefdc4ea45bec5d8be712d7829d82e520c1d310/python/cpython/issues/145142 |
| og:image:alt | Crash report What happened? A reproducer (in the format of Lib/tests/test_free_threading/xxx.py): import unittest from test.support import threading_helper threading_helper.requires_working_threadi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | eendebakpt |
| hostname | github.com |
| expected-hostname | github.com |
| None | d6dc8294eb500fa36bbc57472d61fe87c522f9c3c1d64f70f4926f66a66a7efb |
| 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 | 5741a45fe07e5f377d0d4c524a92e3056acc51bb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width