MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / PretimedHTTPAdapter

Class PretimedHTTPAdapter

dwave/cloud/utils/http.py:33–58  ·  view source on GitHub ↗

Sets a default timeout for all adapter (think session) requests. It is overridden with per-request timeout. But it can not be reset back to infinite wait (``None``). Usage: s = requests.Session() s.mount("http://", PretimedHTTPAdapter(timeout=5)) s.mount("https:

Source from the content-addressed store, hash-verified

31
32
33class PretimedHTTPAdapter(requests.adapters.HTTPAdapter):
34 """Sets a default timeout for all adapter (think session) requests. It is
35 overridden with per-request timeout. But it can not be reset back to
36 infinite wait (``None``).
37
38 Usage:
39
40 s = requests.Session()
41 s.mount("http://", PretimedHTTPAdapter(timeout=5))
42 s.mount("https://", PretimedHTTPAdapter(timeout=5))
43
44 s.get('http://httpbin.org/delay/6') # -> timeouts after 5sec
45 s.get('http://httpbin.org/delay/6', timeout=10) # -> completes after 6sec
46
47 The alternative is to set ``timeout`` on each request manually/explicitly,
48 subclass ``Session``, or monkeypatch ``Session.request()``.
49 """
50
51 def __init__(self, timeout=None, *args, **kwargs):
52 self.timeout = timeout
53 super().__init__(*args, **kwargs)
54
55 def send(self, *args, **kwargs):
56 # can't use setdefault because caller always sets timeout kwarg
57 kwargs['timeout'] = self.timeout
58 return super().send(*args, **kwargs)
59
60
61class TimeoutingHTTPAdapter(PretimedHTTPAdapter):

Callers 2

create_sessionMethod · 0.90
_create_sessionMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected