MCPcopy
hub / github.com/python-trio/trio / sleep

Function sleep

src/trio/_timeouts.py:95–111  ·  view source on GitHub ↗

Pause execution of the current task for the given number of seconds. Args: seconds (float): The number of seconds to sleep. May be zero to insert a checkpoint without actually blocking. Raises: ValueError: if *seconds* is negative or NaN.

(seconds: float)

Source from the content-addressed store, hash-verified

93
94
95async def sleep(seconds: float) -> None:
96 """Pause execution of the current task for the given number of seconds.
97
98 Args:
99 seconds (float): The number of seconds to sleep. May be zero to
100 insert a checkpoint without actually blocking.
101
102 Raises:
103 ValueError: if *seconds* is negative or NaN.
104
105 """
106 if seconds < 0:
107 raise ValueError("`seconds` must be non-negative")
108 if seconds == 0:
109 await trio.lowlevel.checkpoint()
110 else:
111 await sleep_until(trio.current_time() + seconds)
112
113
114class TooSlowError(Exception):

Callers 15

test_mock_clock_autojumpFunction · 0.90
sleeperFunction · 0.90
waiterFunction · 0.90
main_7Function · 0.85
mainFunction · 0.85
sleep_then_startFunction · 0.85
sleep_a_bitFunction · 0.85
sleep_then_crashFunction · 0.85
__anext__Method · 0.85
detachable_coroutineFunction · 0.85

Calls 2

sleep_untilFunction · 0.85
current_timeMethod · 0.45

Tested by 15

test_mock_clock_autojumpFunction · 0.72
sleeperFunction · 0.72
waiterFunction · 0.72
main_7Function · 0.68
mainFunction · 0.68
sleep_then_startFunction · 0.68
sleep_a_bitFunction · 0.68
sleep_then_crashFunction · 0.68
__anext__Method · 0.68
detachable_coroutineFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…