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

Method timeout

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

Calculate a timeout from a deadline. Args: raise_if_elapsed: Whether to raise :exc:`TimeoutError` if the deadline lapsed. Raises: TimeoutError: If the deadline lapsed. Returns: Time left in seconds or :obj:`None`

(self, *, raise_if_elapsed: bool = True)

Source from the content-addressed store, hash-verified

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 14

connectFunction · 0.95
conn_handlerFunction · 0.95
getMethod · 0.95
test_timeout_pendingMethod · 0.95
test_no_timeoutMethod · 0.95
alarmFunction · 0.80
connect_socks_proxyFunction · 0.80
read_connect_responseFunction · 0.80
connect_http_proxyFunction · 0.80
recv_eventsMethod · 0.80

Calls

no outgoing calls

Tested by 4

test_timeout_pendingMethod · 0.76
test_no_timeoutMethod · 0.76