MCPcopy Index your code
hub / github.com/python/cpython / wait

Method wait

Lib/threading.py:330–376  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

wait_forMethod · 0.95

Calls 6

_is_ownedMethod · 0.95
_release_saveMethod · 0.95
_acquire_restoreMethod · 0.95
acquireMethod · 0.45
appendMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected