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

The C API needs to protect state that can be deleted by finalization #134307

Open
Labels
@ZeroIntensity

Description

@ZeroIntensity

In the C API, we have some functions that need to access state that is deleted by finalization. For example,PyGILState_Ensure accesses the gilstate, and that can be concurrently deallocated. In that specific case, I proposed#132510 as a fix, but really, we should have a better way to protect state against a finalizing interpreter. I'm not sure whether to categorize this as a bug or a feature.

I think the best way to do this is through a finalizing counter similar to howPEP-788 proposes preventing interpreter shutdown. So, for functions that don't require an attached thread state, we need something like:

intPySomething_Whatever(PyInterpreterState*interp){if (_PyInterpreterState_CriticalSection(interp)<0) {// Interpreter has finalizedreturn-1;    }/* Do critical operation */_PyInterpreterState_EndCriticalSection(interp);return0;}

Does this approach seem reasonable to everyone?

cc@ericsnowcurrently

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp