Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7ec656e

Browse files
committed
gh-141196: Fix threading.Semaphore documentation inconsistency
The acquire() method documentation stated 'Exactly one thread will be awokenby each call to release()' which became incorrect when the n parameter wasadded to release() in Python 3.9.The release() method documentation was ambiguous about behavior whenn > waiting_threads.Changes:- acquire(): Updated to reflect that release(n) wakes min(j,n) threads where j = waiting threads- release(): Clarified that it wakes 'up to n' threads, or all available if fewer than n are waitingThe fix aligns documentation with actual implementation behavior inLib/threading.py where release(n) calls Condition.notify(n).
1 parentd13ee0a commit7ec656e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

‎Doc/library/threading.rst‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,9 +1144,11 @@ Semaphores also support the :ref:`context management protocol <with-locks>`.
11441144
one and return ``True`` immediately.
11451145
* If the internal counter is zero on entry, block until awoken by a call to
11461146
:meth:`~Semaphore.release`. Once awoken (and the counter is greater
1147-
than 0), decrement the counter by 1 and return ``True``. Exactly one
1148-
thread will be awoken by each call to:meth:`~Semaphore.release`. The
1149-
order in which threads are awoken should not be relied on.
1147+
than 0), decrement the counter by 1 and return ``True``. Each call to
1148+
:meth:`~Semaphore.release` will wake up threads according to its *n*
1149+
parameter (default 1): if *j* threads are waiting and ``release(n)``
1150+
is called, ``min(j, n)`` threads will be awoken. The order in which
1151+
threads are awoken should not be relied on.
11501152

11511153
When invoked with *blocking* set to ``False``, do not block. If a call
11521154
without an argument would block, return ``False`` immediately; otherwise, do
@@ -1166,7 +1168,8 @@ Semaphores also support the :ref:`context management protocol <with-locks>`.
11661168

11671169
Release a semaphore, incrementing the internal counter by *n*. When it
11681170
was zero on entry and other threads are waiting for it to become larger
1169-
than zero again, wake up *n* of those threads.
1171+
than zero again, wake up to *n* of those threads (or all of them if
1172+
fewer than *n* are waiting).
11701173

11711174
..versionchanged::3.9
11721175
Added the *n* parameter to release multiple waiting threads at once.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp