mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Improve the threading.Condition docs.
This commit is contained in:
commit
1c94ff8b68
1 changed files with 5 additions and 3 deletions
|
@ -584,12 +584,14 @@ producer-consumer situation with unlimited buffer capacity::
|
||||||
# Produce one item
|
# Produce one item
|
||||||
with cv:
|
with cv:
|
||||||
make_an_item_available()
|
make_an_item_available()
|
||||||
|
cv.notify()
|
||||||
|
|
||||||
The ``while`` loop checking for the application's condition is necessary
|
The ``while`` loop checking for the application's condition is necessary
|
||||||
because :meth:`~Condition.wait` can return after an arbitrary long time,
|
because :meth:`~Condition.wait` can return after an arbitrary long time,
|
||||||
and other threads may have exhausted the available items in between. This
|
and the condition which prompted the :meth:`~Condition.notify` call may
|
||||||
is inherent to multi-threaded programming. The :meth:`~Condition.wait_for`
|
no longer hold true. This is inherent to multi-threaded programming. The
|
||||||
method can be used to automate the condition checking::
|
:meth:`~Condition.wait_for` method can be used to automate the condition
|
||||||
|
checking, and eases the computation of timeouts::
|
||||||
|
|
||||||
# Consume an item
|
# Consume an item
|
||||||
with cv:
|
with cv:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue