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)
| 93 | |
| 94 | |
| 95 | async 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 | |
| 114 | class TooSlowError(Exception): |
searching dependent graphs…