Skip to content

Commit a3d6d29

Browse files
Bogdandpgeorge
Bogdan
authored andcommitted
urequests: Add timeout, passed to underlying socket if supported.
1 parent dbd8fff commit a3d6d29

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

python-ecosys/urequests/urequests.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ def json(self):
3434

3535

3636
def request(
37-
method, url, data=None, json=None, headers={}, stream=None, parse_headers=True, auth=None
37+
method,
38+
url,
39+
data=None,
40+
json=None,
41+
headers={},
42+
stream=None,
43+
auth=None,
44+
timeout=None,
45+
parse_headers=True,
3846
):
3947
redirect = None # redirection url, None means no redirection
4048
chunked_data = data and getattr(data, "__iter__", None) and not getattr(data, "__len__", None)
@@ -73,6 +81,12 @@ def request(
7381
resp_d = {}
7482

7583
s = usocket.socket(ai[0], usocket.SOCK_STREAM, ai[2])
84+
85+
if timeout is not None:
86+
# Note: settimeout is not supported on all platforms, will raise
87+
# an AttributeError if not available.
88+
s.settimeout(timeout)
89+
7690
try:
7791
s.connect(ai[-1])
7892
if proto == "https:":

0 commit comments

Comments
 (0)