MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / wait

Method wait

tools/python-3.11.9-amd64/Lib/threading.py:295–341  ·  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() ca

(self, timeout=None)

Source from the content-addressed store, hash-verified

293 return True
294
295 def wait(self, timeout=None):
296 """Wait until notified or until a timeout occurs.
297
298 If the calling thread has not acquired the lock when this method is
299 called, a RuntimeError is raised.
300
301 This method releases the underlying lock, and then blocks until it is
302 awakened by a notify() or notify_all() call for the same condition
303 variable in another thread, or until the optional timeout occurs. Once
304 awakened or timed out, it re-acquires the lock and returns.
305
306 When the timeout argument is present and not None, it should be a
307 floating point number specifying a timeout for the operation in seconds
308 (or fractions thereof).
309
310 When the underlying lock is an RLock, it is not released using its
311 release() method, since this may not actually unlock the lock when it
312 was acquired multiple times recursively. Instead, an internal interface
313 of the RLock class is used, which really unlocks it even when it has
314 been recursively acquired several times. Another internal interface is
315 then used to restore the recursion level when the lock is reacquired.
316
317 """
318 if not self._is_owned():
319 raise RuntimeError("cannot wait on un-acquired lock")
320 waiter = _allocate_lock()
321 waiter.acquire()
322 self._waiters.append(waiter)
323 saved_state = self._release_save()
324 gotit = False
325 try: # restore state no matter what (e.g., KeyboardInterrupt)
326 if timeout is None:
327 waiter.acquire()
328 gotit = True
329 else:
330 if timeout > 0:
331 gotit = waiter.acquire(True, timeout)
332 else:
333 gotit = waiter.acquire(False)
334 return gotit
335 finally:
336 self._acquire_restore(saved_state)
337 if not gotit:
338 try:
339 self._waiters.remove(waiter)
340 except ValueError:
341 pass
342
343 def wait_for(self, predicate, timeout=None):
344 """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