Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-136421: Fix crash in _datetime when initialized/finalized concurrently#136620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
neonene wants to merge11 commits intopython:main
base:main
Choose a base branch
Loading
fromneonene:fix-136421

Conversation

neonene
Copy link
Contributor

@neoneneneonene commentedJul 13, 2025
edited by bedevere-appbot
Loading

@neoneneneonene changed the titleFix crash in _datetime when initialized/finalized concurrentlygh-136421: Fix crash in _datetime when initialized/finalized concurrentlyJul 13, 2025
Copy link
Member

@ZeroIntensityZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah, this feels like a really big hack.

But, won't this still initialize the types concurrently anyway? I don't think that's thread-safe, even if the main interpreter sets some of the initial values. AFAICT, the current assumption is that only one interpreter can initialize a static type at a time (because the type lock is per-interpreter, not runtime-wide).

@neonene
Copy link
ContributorAuthor

But, won't this still initialize the types concurrently anyway? I don't think that's thread-safe, even if the main interpreter sets some of the initial values.

I left a comment in your PR:#136583 (comment)

the current assumption is that only one interpreter can initialize a static type at a time (because the type lock is per-interpreter, not runtime-wide).

The runtime state has the initial values as common type data. OTOH, non-initial values such astp_dict are held by each interpreter state. So, once the main interpreter doesinitial initialization, subinterpreters will focus on their interpreter state with their type lock. Also, I saw#129817 being closed as completed. What concern remains?

@ZeroIntensity
Copy link
Member

Also, I saw#129817 being closed as completed. What concern remains?

I think that issue was only fortp_flags ortp_versions_used.#129824 is still open. Just looking at the code forinit_static_type (or more importantly,type_ready), it doesn't look thread-safe for all interpreters.

@neonene
Copy link
ContributorAuthor

According to#129824, the managed staticbuiltin types have the issue despite the fact that the main interpreter initializes them first. Then, the managed staticextension types also have the same issue that cannot be fixed by this PR and yours.

The same will go fortype_ready() if it has issues.

@ZeroIntensity
Copy link
Member

Ugh, I thought that interpreter initialization held the runtime lock. I'll investigate further later this week. We can probably avoid changes to_datetime by just making the static type initialization thread-safe with a big lock or something like that.

That said, I do still think_datetime should be a static module regardless of any static type changes; static types should be in static modules. I'll open a DPO thread at some point.

@neonene
Copy link
ContributorAuthor

neonene commentedJul 14, 2025
edited
Loading

I'll open a DPO thread at some point.

The managed static extension type has been introduced just to work around the issue of the capsule C API, so you need to mention there why you cannot resolve the issue first.

@ZeroIntensity
Copy link
Member

An alternative could be toimmortalize some heap-types and expose them in the capsule.

neonene reacted with thumbs up emoji

@neonene
Copy link
ContributorAuthor

immortalize some heap-types and expose them in the capsule.

Sounds promising, changing thePyDateTimeAPI global variable to something without exposing internals.

@neonene
Copy link
ContributorAuthor

But a heaptype usually holds a corresponding module, which needs to be updated. Or, perhaps immortalize the module as well?

@ZeroIntensity
Copy link
Member

I haven't fully fleshed out the idea yet. I'm thinking we could makePyDateTimeAPI thread-local and then make it aware of the thread state somehow.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ZeroIntensityZeroIntensityZeroIntensity left review comments

@pgansslepganssleAwaiting requested review from pgansslepganssle is a code owner

@abalkinabalkinAwaiting requested review from abalkinabalkin is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@neonene@ZeroIntensity

[8]ページ先頭

©2009-2025 Movatter.jp