Wait until notified or until a timeout occurs. If the calling thread has not acquired the lock when this method is called, a RuntimeError is raised. This method releases the underlying lock, and then blocks until it is awakened by a notify() or notify_all() call for
(self, timeout=None)
| 335 | return True |
| 336 | |
| 337 | def wait(self, timeout=None): |
| 338 | """Wait until notified or until a timeout occurs. |
| 339 | |
| 340 | If the calling thread has not acquired the lock when this method is |
| 341 | called, a RuntimeError is raised. |
| 342 | |
| 343 | This method releases the underlying lock, and then blocks until it is |
| 344 | awakened by a notify() or notify_all() call for the same condition |
| 345 | variable in another thread, or until the optional timeout occurs. Once |
| 346 | awakened or timed out, it re-acquires the lock and returns. |
| 347 | |
| 348 | When the timeout argument is present and not None, it should be a |
| 349 | floating-point number specifying a timeout for the operation in seconds |
| 350 | (or fractions thereof). |
| 351 | |
| 352 | When the underlying lock is an RLock, it is not released using its |
| 353 | release() method, since this may not actually unlock the lock when it |
| 354 | was acquired multiple times recursively. Instead, an internal interface |
| 355 | of the RLock class is used, which really unlocks it even when it has |
| 356 | been recursively acquired several times. Another internal interface is |
| 357 | then used to restore the recursion level when the lock is reacquired. |
| 358 | |
| 359 | """ |
| 360 | if not self._is_owned(): |
| 361 | raise RuntimeError("cannot wait on un-acquired lock") |
| 362 | waiter = _allocate_lock() |
| 363 | waiter.acquire() |
| 364 | self._waiters.append(waiter) |
| 365 | saved_state = self._release_save() |
| 366 | gotit = False |
| 367 | try: # restore state no matter what (e.g., KeyboardInterrupt) |
| 368 | if timeout is None: |
| 369 | waiter.acquire() |
| 370 | gotit = True |
| 371 | else: |
| 372 | if timeout > 0: |
| 373 | gotit = waiter.acquire(True, timeout) |
| 374 | else: |
| 375 | gotit = waiter.acquire(False) |
| 376 | return gotit |
| 377 | finally: |
| 378 | self._acquire_restore(saved_state) |
| 379 | if not gotit: |
| 380 | try: |
| 381 | self._waiters.remove(waiter) |
| 382 | except ValueError: |
| 383 | pass |
| 384 | |
| 385 | def wait_for(self, predicate, timeout=None): |
| 386 | """Wait until a condition evaluates to True. |
no test coverage detected