19
19
20
20
21
21
class FDClient :
22
- def __init__ (self , server_url , compression = True ):
23
- assert (
24
- server_url . startswith ( "http://" ) or server_url . startswith ( " https://")
22
+ def __init__ (self , server_url , compression = True , request_timeout = None ):
23
+ assert server_url . startswith ( "http://" ) or server_url . startswith (
24
+ " https://"
25
25
), "Server URL must start with http:// or https://"
26
26
27
27
assert (
28
28
server_url .count ("/" ) == 2
29
29
), "Server URL must be in the format http(s)://<ip>:<port>"
30
-
30
+
31
31
self .server_url = server_url
32
32
self .local_storage = threading .local ()
33
33
self .requests_session = requests .Session ()
@@ -41,6 +41,7 @@ def __init__(self, server_url, compression=True):
41
41
if msgpack is not None
42
42
else "json"
43
43
)
44
+ self .request_timeout = request_timeout
44
45
45
46
@property
46
47
def _compressor (self ):
@@ -109,6 +110,7 @@ def infer(self, data, unique_id=None, is_async=False):
109
110
},
110
111
data = self ._compressor .compress (data ) if zstandard is not None else data ,
111
112
headers = {"Content-Type" : "application/octet-stream" },
113
+ timeout = self .request_timeout ,
112
114
)
113
115
114
116
if self .input_type == "pickle" :
@@ -168,7 +170,7 @@ def __del__(self):
168
170
print (
169
171
"infer_background_multiple 40" ,
170
172
[
171
- _ .result ()[' success' ]
173
+ _ .result ()[" success" ]
172
174
for _ in client .infer_background_multiple (
173
175
[["this" , b"is" , "some" , "data" ]] * 40
174
176
)
0 commit comments