Skip to content

Make _warnings.c thread-safe in free-threaded build #116664

Closed
@colesbury

Description

@colesbury

Feature or enhancement

The warnings implementation is split between Python (warnings.py) and C (_warnings.c). There are a few bits of code in the C module that are not thread-safe without the GIL:

The Py_SETREF calls are not thread-safe if concurrent writers try to overwrite the same field (e.g., st->once_registry). We can probably use critical sections to make it thread-safe.

get_once_registry:

Py_SETREF(st->once_registry, registry);

get_default_action:

Py_SETREF(st->default_action, default_action);

get_filter:

Py_SETREF(st->filters, warnings_filters);

Some uses of borrowed references are likely not thread-safe

  • _PyDict_GetItemWithError (replace with PyDict_GetItemRef?)

Linked PRs

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy