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