MCPcopy Index your code
hub / github.com/python-websockets/websockets / Deadline

Class Deadline

src/websockets/sync/utils.py:9–45  ·  view source on GitHub ↗

Manage timeouts across multiple steps. Args: timeout: Time available in seconds or :obj:`None` if there is no limit.

Source from the content-addressed store, hash-verified

7
8
9class Deadline:
10 """
11 Manage timeouts across multiple steps.
12
13 Args:
14 timeout: Time available in seconds or :obj:`None` if there is no limit.
15
16 """
17
18 def __init__(self, timeout: float | None) -> None:
19 self.deadline: float | None
20 if timeout is None:
21 self.deadline = None
22 else:
23 self.deadline = time.monotonic() + timeout
24
25 def timeout(self, *, raise_if_elapsed: bool = True) -> float | None:
26 """
27 Calculate a timeout from a deadline.
28
29 Args:
30 raise_if_elapsed: Whether to raise :exc:`TimeoutError`
31 if the deadline lapsed.
32
33 Raises:
34 TimeoutError: If the deadline lapsed.
35
36 Returns:
37 Time left in seconds or :obj:`None` if there is no limit.
38
39 """
40 if self.deadline is None:
41 return None
42 timeout = self.deadline - time.monotonic()
43 if raise_if_elapsed and timeout <= 0:
44 raise TimeoutError("timed out")
45 return timeout

Callers 9

connectFunction · 0.85
recv_eventsMethod · 0.85
send_contextMethod · 0.85
conn_handlerFunction · 0.85
getMethod · 0.85
test_timeout_pendingMethod · 0.85
test_no_timeoutMethod · 0.85

Calls

no outgoing calls

Tested by 4

test_timeout_pendingMethod · 0.68
test_no_timeoutMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…