Skip to content

Use critical sections to protect I/O objects (in --disable-gil builds) #111965

Closed
@colesbury

Description

@colesbury

Feature or enhancement

The I/O objects, like io.BufferedIOBase, io.TextIOWrapper, and io.StringIO have internal state that would not be thread-safe without the GIL.

We should be able to mostly use Argument Clinic's (AC) support for "critical sections" to guard methods on these objects. For operations that don't use AC, we can either convert them to use AC or write the Py_BEGIN_CRITICAL_SECTION/Py_END_CRITICAL_SECTION manually.

For context, here are the similar modifications in the nogil-3.12 fork, but the implementation in CPython 3.13 will be a bit different (no need for extra locks, use the syntax from #111903):

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions