This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Prepare runtime/interp/thread state and init for upcoming changes.
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eric.snow Nosy List: Quentin.Pradet, eric.snow, miss-islington
Priority: normal Keywords: patch

Created on 2021-12-07 20:24 by eric.snow, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 29970 merged eric.snow, 2021-12-07 20:29
PR 29971 merged eric.snow, 2021-12-07 20:29
PR 29972 merged eric.snow, 2021-12-07 20:47
PR 29973 merged eric.snow, 2021-12-07 21:00
PR 29977 merged eric.snow, 2021-12-08 00:36
PR 29978 merged eric.snow, 2021-12-08 01:14
PR 29998 merged eric.snow, 2021-12-09 01:05
Messages (10)
msg407963 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2021-12-07 20:24
There are a few things in `_PyRuntimeState`, `PyInterpreterState`, `PyThreadState`, and there initialization (Python/pystate.c & Python/pylifecycle.c) that would benefit from some minor cleanup.  Normally I wouldn't bother (due to the cost of churn), but such cleanup would help with other changes I'm working on.

The cleanup includes:

* move thread related interpreter state to `PyInterpreterState.threads`
* return void from `_PyEval_InitState()`
* separate Py*State initialization from creation
* distinguish between initialized-to-safe-state and ready-to-use
* separate init for global types/objects into phases: object state vs. global objects vs. global types
msg407967 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2021-12-07 21:02
New changeset 8262c96bcc1841188866c1b022d9087e89639d98 by Eric Snow in branch 'main':
bpo-46008: Return void from _PyEval_InitState(). (gh-29970)
https://github.com/python/cpython/commit/8262c96bcc1841188866c1b022d9087e89639d98
msg407969 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2021-12-07 21:03
New changeset 313f92a57bc3887026ec16adb536bb2b7580ce47 by Eric Snow in branch 'main':
bpo-46008: Move thread-related interpreter state into a sub-struct. (gh-29971)
https://github.com/python/cpython/commit/313f92a57bc3887026ec16adb536bb2b7580ce47
msg407972 - (view) Author: miss-islington (miss-islington) Date: 2021-12-07 21:38
New changeset 9b577cd01f66512b503115c0fdbf0734edfd5f8a by Eric Snow in branch 'main':
bpo-46008: Use PyMem_RawCalloc() to allocate PyThreadState. (GH-29972)
https://github.com/python/cpython/commit/9b577cd01f66512b503115c0fdbf0734edfd5f8a
msg407989 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2021-12-08 00:26
New changeset 1f384e318481532323bb9076f4447bc02da07209 by Eric Snow in branch 'main':
bpo-46008: Stop calling _PyThreadState_Init() in new_threadstate(). (gh-29973)
https://github.com/python/cpython/commit/1f384e318481532323bb9076f4447bc02da07209
msg407991 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2021-12-08 01:56
New changeset 758b74e71eb22e1e83a9eb937d1c015e461745a1 by Eric Snow in branch 'main':
bpo-46008: Add _PyInterpreterState_Main(). (gh-29978)
https://github.com/python/cpython/commit/758b74e71eb22e1e83a9eb937d1c015e461745a1
msg407992 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2021-12-08 01:59
New changeset 32a67246b0d1e08cd50fc3bfa58052cfeb515b2e by Eric Snow in branch 'main':
bpo-46008: Move Py*State init into distinct functions. (gh-29977)
https://github.com/python/cpython/commit/32a67246b0d1e08cd50fc3bfa58052cfeb515b2e
msg407993 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2021-12-08 02:01
At this point all the changes I was considering have been made, except for splitting type/object init into logical phases.  That may or may not happen.  Regardless, it can be done in a new issue.
msg408158 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2021-12-09 19:59
New changeset c8749b578324ad4089c8d014d9136bc42b065343 by Eric Snow in branch 'main':
bpo-46008: Make runtime-global object/type lifecycle functions and state consistent. (gh-29998)
https://github.com/python/cpython/commit/c8749b578324ad4089c8d014d9136bc42b065343
msg410168 - (view) Author: Quentin Pradet (Quentin.Pradet) * Date: 2022-01-09 20:58
For what it's worth, this refactoring led to a 100% reproducible crash on my Fedora laptop: https://bugs.python.org/issue46320. (And led to various crashes in urllib3's CI, but they were more random.)
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90166
2022-01-09 20:58:25Quentin.Pradetsetnosy: + Quentin.Pradet
messages: + msg410168
2021-12-09 19:59:37eric.snowsetmessages: + msg408158
2021-12-09 01:05:34eric.snowsetpull_requests: + pull_request28221
2021-12-08 02:01:39eric.snowsetstatus: open -> closed
resolution: fixed
messages: + msg407993

stage: patch review -> resolved
2021-12-08 01:59:55eric.snowsetmessages: + msg407992
2021-12-08 01:56:14eric.snowsetmessages: + msg407991
2021-12-08 01:14:46eric.snowsetpull_requests: + pull_request28204
2021-12-08 00:36:15eric.snowsetpull_requests: + pull_request28203
2021-12-08 00:26:39eric.snowsetmessages: + msg407989
2021-12-07 21:38:01miss-islingtonsetnosy: + miss-islington
messages: + msg407972
2021-12-07 21:03:58eric.snowsetmessages: + msg407969
2021-12-07 21:02:35eric.snowsetmessages: + msg407967
2021-12-07 21:00:39eric.snowsetpull_requests: + pull_request28198
2021-12-07 20:47:38eric.snowsetpull_requests: + pull_request28197
2021-12-07 20:29:37eric.snowsetpull_requests: + pull_request28196
2021-12-07 20:29:33eric.snowsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request28195
2021-12-07 20:24:26eric.snowcreate