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 — The os.sched_yield() implementation in posixmodule.c doesn't release the GIL · Issue #96078 · python/cpython

The os.sched_yield() implementation in posixmodule.c doesn't release the GIL #96078

New issue
Copy link
New issue
Copy link
Closed
Closed
The os.sched_yield() implementation in posixmodule.c doesn't release the GIL#96078
Copy link
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.12only security fixesonly security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@FilipDepta
FilipDepta
opened on Aug 18, 2022
Issue body actions

I've reviewed the main branch and the GIL isn't released: https://github.com/python/cpython/blob/main/Modules/posixmodule.c#L7060

The forum thread: https://discuss.python.org/t/does-the-os-sched-yield-release-the-gil/18301

Expected: The GIL is released before sched_yield() and acquired after that.

Activity

  1. FilipDepta
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Aug 18, 2022
  2. eryksun
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    3.11only security fixesonly security fixes
    3.10 (EOL)end of lifeend of life
    3.12only security fixesonly security fixes
    on Aug 18, 2022
  3. eryksun commented on Aug 18, 2022

    @eryksun
    eryksun
    on Aug 18, 2022
    Contributor
    More actions

    Interestingly, os.sched_yield() was added 11 years ago, and no one has ever mentioned this oversight. I guess the users, if any1, are satisfied that it can only yield execution to ready threads that aren't waiting to acquire the GIL. The behavior was never documented, so I'm tagging this as a bug in 3.10+.

    Footnotes

    1. The man page for sched_yield() in Linux says the behavior is "unspecified" if the process isn't using a deterministic realtime scheduler such as SCHED_FIFO (first in, first out) or SCHED_RR (round robin). I'm guessing it's not common for Python applications to use realtime scheduling. ↩

  4. FilipDepta commented on Aug 19, 2022

    @FilipDepta
    FilipDepta
    on Aug 19, 2022
    Author
    More actions

    [...] using a deterministic realtime scheduler such as SCHED_FIFO (first in, first out) or SCHED_RR (round robin). I'm guessing it's not common for Python applications to use realtime scheduling. ↩

    That is exactly what I do - using SHED_FIFO with two threads I sometimes call os.sched_yield() to ensure that the second thread was executed as freshly as possible.

    Maybe it's a good idea to add an annotation in docs for older cpythons that os.sched_yield() doesn't release the GIL?

  5. corona10
    added 2 commits that reference this issue on Oct 6, 2022

    pythongh-96078: os.sched_yield release the GIL while calling sched_yi…

    5f150a8

    pythongh-96078: os.sched_yield release the GIL while calling sched_yi…

    40c5725
  6. benjaminp
    closed this as completedin b9d2e81on Oct 6, 2022
  7. carljm
    added a commit that references this issue on Oct 6, 2022

    Merge branch 'main' into dictwatch

    This issue will close once commit e5d2169 is merged into the 'main' branch.
    e5d2169
  8. miss-islington
    added 4 commits that reference this issue on Oct 7, 2022

    fixes pythongh-96078: os.sched_yield release the GIL while calling sc…

    This issue will close once commit 920e025 is merged into the 'master' branch.
    920e025

    fixes pythongh-96078: os.sched_yield release the GIL while calling sc…

    This issue will close once commit 4a38944 is merged into the 'master' branch.
    4a38944

    fixes gh-96078: os.sched_yield release the GIL while calling sched_yi…

    This issue will close once commit e39b511 is merged into the 'main' branch.
    e39b511

    fixes gh-96078: os.sched_yield release the GIL while calling sched_yi…

    This issue will close once commit 11945f2 is merged into the 'main' branch.
    11945f2
  9. carljm
    added a commit that references this issue on Oct 8, 2022

    Merge branch 'main' into typewatch

    This issue will close once commit 415ed49 is merged into the 'main' branch.
    415ed49
  10. mpage
    added a commit that references this issue on Oct 11, 2022

    fixes pythongh-96078: os.sched_yield release the GIL while calling sc…

    This issue will close once commit 0c970bd is merged into the 'main' branch.
    0c970bd
  11. serhiy-storchaka
    added a commit that references this issue on Aug 9, 2026

    fixes pythongh-96078: os.sched_yield release the GIL while calling sc…

    This issue will close once commit b9d2e81 is merged into the 'main' branch.
    b9d2e81
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.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.12only security fixesonly security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — 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.