Skip to content

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Jul 21, 2025

_datetime is a special module, because it's the only non-builtin C extension that contains static types. As such, it would initialize static types in the module's execution function, which can run concurrently. Since static type initialization is not thread-safe, this caused crashes. This fixes it by moving the initialization of _datetime's static types to interpreter startup (where all other static types are initialized), which is already properly protected through other locks.
(cherry picked from commit a109606)

Co-authored-by: Peter Bierma [email protected]

…tialization (pythonGH-136583)

`_datetime` is a special module, because it's the only non-builtin C extension that contains static types. As such, it would initialize static types in the module's execution function, which can run concurrently. Since static type initialization is not thread-safe, this caused crashes. This fixes it by moving the initialization of `_datetime`'s static types to interpreter startup (where all other static types are initialized), which is already properly protected through other locks.
(cherry picked from commit a109606)

Co-authored-by: Peter Bierma <[email protected]>
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @ZeroIntensity for commit 4912c10 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F136943%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 21, 2025
@ZeroIntensity
Copy link
Member

@hugovk Just want to make sure that this one is good with you before landing it. It fixes crashes with the subinterpreter APIs, but is also a risky change in the sense that we're making _datetime static (and thus required to build CPython).

@hugovk
Copy link
Member

hugovk commented Jul 21, 2025

@ZeroIntensity Go ahead when the buildbots are ready, thanks for the ping.

@ZeroIntensity
Copy link
Member

Most of them have passed, I'm confident that this is good to go.

@ZeroIntensity ZeroIntensity merged commit ecd97ca into python:3.14 Jul 21, 2025
123 of 126 checks passed
@zanieb
Copy link
Contributor

zanieb commented Jul 22, 2025

For future reference, this did break our downstream build at astral-sh/python-build-standalone#710 — it's not a big deal but I was surprised to see a change like this in the release candidate. Seems like a decent trade-off given it was fixing crashes, but figure the signal might be helpful.

@geofft
Copy link
Contributor

geofft commented Jul 22, 2025

Yes but that's because we're reimplementing Modules/Setup for complicated reasons, right? If I understand correctly, the build system in CPython was stable into the release candidate, we're just choosing to mess around with implementation details of the build system that I don't think CPython should be expected to keep stable, if I understand correctly. (And our build correctly failed because we have checks that our reimplementation matches what is actually distributed by CPython.)

@zanieb
Copy link
Contributor

zanieb commented Jul 23, 2025

Yeah our situation is bespoke, but changes to how extension modules are built are still significant. I'm not really sure what there is to debate though, since I agree with you and was just leaving the note for reference :)

@ZeroIntensity
Copy link
Member

Thanks for the heads up. Would it be helpful to perhaps document this in the whatsnew somewhere?

@zanieb
Copy link
Contributor

zanieb commented Jul 23, 2025

I don't think that'd make a difference to me, I found this pull request pretty easily. Maybe another downstream will feel differently though.

kumaraditya303 pushed a commit to miss-islington/cpython that referenced this pull request Sep 9, 2025
…ter initialization (pythonGH-136583) (pythonGH-136943)

pythongh-136421: Load `_datetime` static types during interpreter initialization (pythonGH-136583)

`_datetime` is a special module, because it's the only non-builtin C extension that contains static types. As such, it would initialize static types in the module's execution function, which can run concurrently. Since static type initialization is not thread-safe, this caused crashes. This fixes it by moving the initialization of `_datetime`'s static types to interpreter startup (where all other static types are initialized), which is already properly protected through other locks.
(cherry picked from commit a109606)

Co-authored-by: Peter Bierma <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants