mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
#1674032: return value of flag from Event.wait(). OKed by Guido.
This commit is contained in:
parent
1d7d5325be
commit
ef660e8e50
3 changed files with 12 additions and 4 deletions
|
@ -696,14 +696,20 @@ An event object manages an internal flag that can be set to true with the
|
||||||
|
|
||||||
.. method:: Event.wait([timeout])
|
.. method:: Event.wait([timeout])
|
||||||
|
|
||||||
Block until the internal flag is true. If the internal flag is true on entry,
|
Block until the internal flag is true. If the internal flag is true on entry,
|
||||||
return immediately. Otherwise, block until another thread calls :meth:`set` to
|
return immediately. Otherwise, block until another thread calls :meth:`set`
|
||||||
set the flag to true, or until the optional timeout occurs.
|
to set the flag to true, or until the optional timeout occurs.
|
||||||
|
|
||||||
When the timeout argument is present and not ``None``, it should be a floating
|
When the timeout argument is present and not ``None``, it should be a floating
|
||||||
point number specifying a timeout for the operation in seconds (or fractions
|
point number specifying a timeout for the operation in seconds (or fractions
|
||||||
thereof).
|
thereof).
|
||||||
|
|
||||||
|
This method returns the internal flag on exit, so it will always return
|
||||||
|
``True`` except if a timeout is given and the operation times out.
|
||||||
|
|
||||||
|
.. versionchanged:: 2.7
|
||||||
|
Previously, the method always returned ``None``.
|
||||||
|
|
||||||
|
|
||||||
.. _timer-objects:
|
.. _timer-objects:
|
||||||
|
|
||||||
|
|
|
@ -186,7 +186,8 @@ class ThreadTests(unittest.TestCase):
|
||||||
# Now raise an exception in the worker thread.
|
# Now raise an exception in the worker thread.
|
||||||
if verbose:
|
if verbose:
|
||||||
print " waiting for worker thread to get started"
|
print " waiting for worker thread to get started"
|
||||||
worker_started.wait()
|
ret = worker_started.wait()
|
||||||
|
self.assertTrue(ret)
|
||||||
if verbose:
|
if verbose:
|
||||||
print " verifying worker hasn't exited"
|
print " verifying worker hasn't exited"
|
||||||
self.assert_(not t.finished)
|
self.assert_(not t.finished)
|
||||||
|
|
|
@ -391,6 +391,7 @@ class _Event(_Verbose):
|
||||||
try:
|
try:
|
||||||
if not self.__flag:
|
if not self.__flag:
|
||||||
self.__cond.wait(timeout)
|
self.__cond.wait(timeout)
|
||||||
|
return self.__flag
|
||||||
finally:
|
finally:
|
||||||
self.__cond.release()
|
self.__cond.release()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue