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 — Multiprocessing Semaphore and BoundedSemaphore - incomplete features ('get_value' missing) on MacOSX. · Issue #125828 · python/cpython

Multiprocessing Semaphore and BoundedSemaphore - incomplete features ('get_value' missing) on MacOSX. #125828

New issue
Copy link
New issue
Copy link
Open
Open
Multiprocessing Semaphore and BoundedSemaphore - incomplete features ('get_value' missing) on MacOSX.#125828
Copy link
Labels
OS-macstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-multiprocessingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@YvesDup
YvesDup
opened on Oct 22, 2024
Issue body actions

Bug report

Bug description:

I've been working on this PR: Adding multiprocessing queue shutdown feature for a while on my Mac machine. I've come up with a solution for this new feature and wanted to check that it also worked on Linux. However, I had forgotten that BoundedSemaphore is not fully functional on MacOSX. In fact, there's no check for exceeding the upper bound. See this example:

import multiprocessing as mp
bs = mp.BoundedSemaphore(2)
print(bs) # <BoundedSemaphore(value=unknown, maxvalue=2)>  note invalid representation string 
bs.release() # Succeed with MacOSX, Raise an exception on Linux 

I had to revise my solution because it was invalid on Linux. Such a shame, I wasted a lot of time. I checked on the documentation a few days ago . There is not a specific warning about this case.

As a reminder, the initial reason is the absence of the sem_getvalue C function in the MacOSX semaphore implementation. This prevents retrieval of the current semaphore value. It also prevents the Semaphore use as a shared counter. This issue is (very ?) old, and still hasn't been solved from Apple, could a workaround be implemented on MacOSX, so that Semaphore and BoundedSemaphore would have the same functionalities as Linux/Win.

A workaround (in Python) would be to use a shared value and to revise the acquire and release methods in order to emulate the semaphore internal counter. It is quite possible that this solution would greatly reduce performance.

I've already done a lot of tests (See the attached draft PR). And also, this solution should fix the representation strings that are currently wrong.

Before going any further, I was wondering if there's a reason why no patch attempt has been implemented ? And was there an old discussion about this already ?

Thanks for your feedback

CPython versions tested on:

3.10, 3.11, 3.12, 3.13, CPython main branch

Operating systems tested on:

macOS

Linked PRs

  • gh-125828 : Fix 'get_value' missing on [Bounded]Semaphore on multiprocessing MacOSX #125829
  • gh-125828 : Fix 'get_value' missing for [Bounded]Semaphore on multiprocessing MacOSX - C workaround #130913

Activity

  1. YvesDup
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Oct 22, 2024
  2. picnixz
    added
    topic-multiprocessing
    on Oct 22, 2024
  3. gpshead
    added this to Multiprocessing issueson Jun 26, 2025
  4. YvesDup commented on Jun 2, 2026

    @YvesDup
    YvesDup
    on Jun 2, 2026
    ContributorAuthor
    More actions

    It was a long journey during which I dived into Python code and macOS system calls, exploring the mechanics of semaphores.
    After a long period of work, I am pleased to present today two alternatives to address the missing get_value method in multiprocessing.Semaphore on macOS.

    1. A first workaround written in Python, creating a dedicated class with two shared multiprocessing.Value to emulate the internal counters.
    2. An another workaround written in C, located in _multiprocessing.Semlock, as suggested by @picnixz and @freakboy3742.
      This fix relies on using shared memory protected by a system lock, plus adding a mutex for each semaphore.

    I really hope that a Python core developer will be able to look into these two options.

  5. picnixz
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Jun 2, 2026
  6. YvesDup commented on Jun 4, 2026

    @YvesDup
    YvesDup
    on Jun 4, 2026
    ContributorAuthor
    More actions

    I suggest to add the 'OS-mac' topic.

  7. freakboy3742
    added
    OS-mac
    on Jun 5, 2026
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

    OS-macstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-multiprocessingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • Multiprocessing issues
      Status
      No status
      Show more project fields

    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.