Title: `PyThreadState` and `PyInterpreterState` are not freed · Issue #99205 · python/cpython · GitHub
Open Graph Title: `PyThreadState` and `PyInterpreterState` are not freed · Issue #99205 · python/cpython
X Title: `PyThreadState` and `PyInterpreterState` are not freed · Issue #99205 · python/cpython
Description: The following test program gains about 10M per second under top, on Python 3.11 only (confirmed for all development stages: 3.11.0a4, 3.11.0b1, 3.11.0rc1, 3.11.0) . 3.10 shows no memory growth. from threading import Thread while True: t1...
Open Graph Description: The following test program gains about 10M per second under top, on Python 3.11 only (confirmed for all development stages: 3.11.0a4, 3.11.0b1, 3.11.0rc1, 3.11.0) . 3.10 shows no memory growth. fro...
X Description: The following test program gains about 10M per second under top, on Python 3.11 only (confirmed for all development stages: 3.11.0a4, 3.11.0b1, 3.11.0rc1, 3.11.0) . 3.10 shows no memory growth. fro...
Opengraph URL: https://github.com/python/cpython/issues/99205
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`PyThreadState` and `PyInterpreterState` are not freed","articleBody":"The following test program gains about 10M per second under top, on Python 3.11 only (confirmed for all development stages: 3.11.0a4, 3.11.0b1, 3.11.0rc1, 3.11.0) . 3.10 shows no memory growth.\r\n\r\n```py\r\nfrom threading import Thread\r\n\r\nwhile True:\r\n t1 = Thread()\r\n t1.start()\r\n```\r\n\r\nFor direct results, here's the same program using the `resource` module that I just saw used over at #98467:\r\n\r\n```py\r\nfrom threading import Thread\r\nimport resource\r\n\r\nprint(\"Before\", resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024, \"MB\")\r\n\r\ni = 0\r\n\r\nwhile True:\r\n i += 1\r\n t1 = Thread()\r\n t1.start()\r\n if i % 10000 == 0:\r\n print(\r\n f\"memory after {i} iterations:\",\r\n resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024,\r\n \"MB\",\r\n )\r\n```\r\n\r\nThe above program under Py 3.11.0 prints:\r\n\r\n```\r\n$ .venv-3.11/bin/python test5.py \r\nBefore 8.14453125 MB\r\nmemory after 10000 iterations: 11.6875 MB\r\nmemory after 20000 iterations: 15.30078125 MB\r\nmemory after 30000 iterations: 18.65234375 MB\r\nmemory after 40000 iterations: 22.26171875 MB\r\nmemory after 50000 iterations: 25.87109375 MB\r\nmemory after 60000 iterations: 29.22265625 MB\r\nmemory after 70000 iterations: 32.83203125 MB\r\nmemory after 80000 iterations: 36.44140625 MB\r\nmemory after 90000 iterations: 39.78125 MB\r\nmemory after 100000 iterations: 43.390625 MB\r\n...\r\n```\r\n\r\nunder Python 3.10 it prints:\r\n\r\n```\r\n$ .venv-3.10/bin/python test5.py \r\nBefore 9.25 MB\r\nmemory after 10000 iterations: 9.46484375 MB\r\nmemory after 20000 iterations: 9.47265625 MB\r\nmemory after 30000 iterations: 9.47265625 MB\r\nmemory after 40000 iterations: 9.47265625 MB\r\nmemory after 50000 iterations: 9.47265625 MB\r\nmemory after 60000 iterations: 9.47265625 MB\r\nmemory after 70000 iterations: 9.47265625 MB\r\nmemory after 80000 iterations: 9.47265625 MB\r\n```\r\n\r\n\r\nthe issue looks extremely similar to another one we just fixed in greenlet, over at https://github.com/python-greenlet/greenlet/issues/328, although this one is much more surprising. Issue #98467 might also be related.\r\n\r\n\r\nEnvironment:\r\n```\r\n$ uname -a\r\nLinux photon3 5.17.14-200.fc35.x86_64 #1 SMP PREEMPT Thu Jun 9 14:02:42 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux\r\n\r\n$ python3\r\nPython 3.11.0 (main, Nov 5 2022, 23:27:22) [GCC 11.3.1 20220421 (Red Hat 11.3.1-3)] on linux\r\n```\r\n\n\n\u003c!-- gh-pr-number: gh-99268 --\u003e\n* PR: gh-99268\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99301 --\u003e\n* PR: gh-99301\n\u003c!-- /gh-pr-number --\u003e\n\n\n\u003c!-- gh-pr-number: gh-99385 --\u003e\n* PR: gh-99385\n\u003c!-- /gh-pr-number --\u003e\n","author":{"url":"https://github.com/zzzeek","@type":"Person","name":"zzzeek"},"datePublished":"2022-11-07T15:11:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":13},"url":"https://github.com/99205/cpython/issues/99205"}
| 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:399d40f1-7b3a-bf60-3f0c-62d38a143604 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ADEC:240939:F7FCB7:14BD54A:69699137 |
| html-safe-nonce | 202254e168aec99feb04411ac36282aea4049d8f4487500076642a4f5d3e1d63 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBREVDOjI0MDkzOTpGN0ZDQjc6MTRCRDU0QTo2OTY5OTEzNyIsInZpc2l0b3JfaWQiOiI4MjE2ODMzNTg5Mzc4NjUwNDIzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8202636c7b88925d800166179e92afaf3e0aba69be67874aba728efc66fa066f |
| hovercard-subject-tag | issue:1438527053 |
| 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/99205/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ae527d7dffc27062f53c89cf4d56064dd3ac0e2c41f85f011ea89e133686e073/python/cpython/issues/99205 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ae527d7dffc27062f53c89cf4d56064dd3ac0e2c41f85f011ea89e133686e073/python/cpython/issues/99205 |
| og:image:alt | The following test program gains about 10M per second under top, on Python 3.11 only (confirmed for all development stages: 3.11.0a4, 3.11.0b1, 3.11.0rc1, 3.11.0) . 3.10 shows no memory growth. fro... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zzzeek |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3542e147982176a7ebaa23dfb559c8af16f721c03ec560c68c56b64a0f35e751 |
| 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 | af80af7cc9e3de9c336f18b208a600950a3c187c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width