Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional argument to Semaphore.release for releasing multiple threads #55187

Closed
rhettinger opened this issue Jan 22, 2011 · 6 comments
Closed
Assignees
Labels
3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@rhettinger
Copy link
Contributor

BPO 10978
Nosy @tim-one, @rhettinger, @pitrou, @MojoVampire
PRs
  • bpo-10978: Semaphores can release multiple threads at a time #15588
  • Files
  • sem.diff: Patch to threading.py
  • multirelease.diff: Update patch to Py3.5. Add test and docs
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2019-08-29.08:45:42.904>
    created_at = <Date 2011-01-22.00:15:34.025>
    labels = ['type-feature', 'library', '3.9']
    title = 'Add optional argument to Semaphore.release for releasing multiple threads'
    updated_at = <Date 2019-08-29.08:45:42.904>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2019-08-29.08:45:42.904>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2019-08-29.08:45:42.904>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2011-01-22.00:15:34.025>
    creator = 'rhettinger'
    dependencies = []
    files = ['20483', '35718']
    hgrepos = []
    issue_num = 10978
    keywords = ['patch']
    message_count = 6.0
    messages = ['126804', '135005', '221028', '221213', '221585', '350757']
    nosy_count = 5.0
    nosy_names = ['tim.peters', 'rhettinger', 'pitrou', 'neologix', 'josh.r']
    pr_nums = ['15588']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue10978'
    versions = ['Python 3.9']

    @rhettinger
    Copy link
    Contributor Author

    Call sem.release(5) would have the same effect as:

    with lock:
        for i in range(5):
             sem.release()

    The use case is when a single semaphore is holding up multiple threads and needs to release them all. According to "The Little Book of Semaphores <http://greenteapress.com/semaphores/\>", this is a common design pattern.

    Basic patch attached. If the proposal meets with acceptance, will add tests and a doc update.

    @rhettinger rhettinger added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir labels Jan 22, 2011
    @rhettinger rhettinger self-assigned this Mar 23, 2011
    @pitrou
    Copy link
    Member

    pitrou commented May 2, 2011

    Your patch uses tabs for indentation. Otherwise, looks good on the principle.

    @pitrou pitrou added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels May 2, 2011
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jun 19, 2014

    Seems good to proceed as there are no dissenters.

    @rhettinger
    Copy link
    Contributor Author

    Updated patch (with tests and docs).

    @MojoVampire
    Copy link
    Mannequin

    MojoVampire mannequin commented Jun 25, 2014

    Never know whether to comment on issue itself, but just in case:

    There are issues with the patch when n < 0 is passed, as n is not sanity checked, which would break the Semaphore invariant (value must be >= 0). n == 0 is also a weird value, but harmless if passed; release(0) would acquire and release the lock but otherwise act as a noop.

    @rhettinger rhettinger added the 3.9 only security fixes label Aug 29, 2019
    @rhettinger
    Copy link
    Contributor Author

    New changeset 35f6301 by Raymond Hettinger in branch 'master':
    bpo-10978: Semaphores can release multiple threads at a time (GH-15588)
    35f6301

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants