GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use critical sections to protect I/O objects (in `--disable-gil` builds) · Issue #111965 · python/cpython

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

New issue
Copy link
New issue
Copy link
Closed
Closed
Use critical sections to protect I/O objects (in --disable-gil builds)#111965
Copy link
Labels
3.13only security fixesonly security fixestopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Description

@colesbury
colesbury
opened on Nov 10, 2023
Issue body actions

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):

  • colesbury/nogil-3.12@ffade9d6f6 (PR by @Mayuresh16)
  • colesbury/nogil-3.12@5b83c16dcd (PR by @aisk)
  • colesbury/nogil-3.12@6323ca60f9 (PR by @aisk)

Linked PRs

  • gh-111965: Using critical sections to make io.StringIO thread safe. #112116
  • gh-111965: Use critical sections to make io.TextIOWrapper thread safe #112193
  • gh-111965: Use critical sections to make io.BufferedIOBase and its related classes thread safe #112298

Activity

  1. colesbury
    added
    type-featureA feature request or enhancementA feature request or enhancement
    3.13only security fixesonly security fixes
    topic-free-threading
    on Nov 10, 2023
  2. aisk commented on Nov 17, 2023

    @aisk
    aisk
    on Nov 17, 2023
    Member
    More actions

    The TextIOBase should be a base class and it's methods is just raise exceptions, so I think it dosen't need critical section protect. Is it a typo to TextIOWrapper? @colesbury

  3. colesbury commented on Nov 17, 2023

    @colesbury
    colesbury
    on Nov 17, 2023
    ContributorAuthor
    More actions

    Yes, thanks, it should say TextIOWrapper. I've edited the issue.

  4. corona10
    added 2 commits that reference this issue on Nov 18, 2023

    gh-111965: Use critical sections to make io.TextIOWrapper thread safe (…

    1a969b4

    gh-111965: Using critical sections to make ``io.StringIO`` thread saf…

    77d9f1e
  5. sobolevn commented on Nov 20, 2023

    @sobolevn
    sobolevn
    on Nov 20, 2023
    Member
    More actions

    Sorry, what about _pyio?

  6. colesbury commented on Nov 20, 2023

    @colesbury
    colesbury
    on Nov 20, 2023
    ContributorAuthor
    More actions

    @sobolevn, any specific concerns? I didn't see anything that looked like it required locking, but I may have missed something.

    Reacted by sobolevn
  7. sobolevn commented on Nov 20, 2023

    @sobolevn
    sobolevn
    on Nov 20, 2023
    Member
    More actions

    No, no specific questions :)
    I hoe that our new tests for threaded IO will catch any potential differences between two implementations 👍

  8. Mayuresh16 commented on Nov 21, 2023

    @Mayuresh16
    Mayuresh16
    on Nov 21, 2023
    Contributor
    More actions

    @colesbury Hi, I would like to give it a try for io.BufferedXXX implementation and will be happy to start my first open-source contribution with CPython based on my knowledge and understanding of the tools. 😅

  9. corona10
    added a commit that references this issue on Nov 22, 2023

    gh-111965: Use critical sections to make io.BufferedIOBase and its re…

    fef6fb8
  10. sobolevn commented on Nov 22, 2023

    @sobolevn
    sobolevn
    on Nov 22, 2023
    Member
    More actions

    Looks like it is done! 🎉

    Reacted by Sam Gross, An Long and Mayuresh Kedari
  11. colesbury
    closed this as completedon Nov 22, 2023
  12. aisk
    added 3 commits that reference this issue on Feb 11, 2024

    pythongh-111965: Use critical sections to make io.TextIOWrapper threa…

    7146788

    pythongh-111965: Using critical sections to make ``io.StringIO`` thre…

    55a49a1

    pythongh-111965: Use critical sections to make io.BufferedIOBase and …

    5b9aa3a
  13. Glyphack
    added 3 commits that reference this issue on Sep 2, 2024

    pythongh-111965: Use critical sections to make io.TextIOWrapper threa…

    c937228

    pythongh-111965: Using critical sections to make ``io.StringIO`` thre…

    e70a4a4

    pythongh-111965: Use critical sections to make io.BufferedIOBase and …

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixesonly security fixestopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.