add timeout

This commit is contained in:
Ren Tatsumoto 2023-08-21 08:34:06 +03:00
parent a71a2a389c
commit aa51c91851

View file

@ -16,7 +16,10 @@ def request(action, **params):
def invoke(action, **params): def invoke(action, **params):
request_json = json.dumps(request(action, **params)).encode('utf-8') request_json = json.dumps(request(action, **params)).encode('utf-8')
response = json.load(urllib.request.urlopen(urllib.request.Request('http://127.0.0.1:8765', request_json))) response = json.load(urllib.request.urlopen(
urllib.request.Request('http://127.0.0.1:8765', request_json),
timeout=10
))
if len(response) != 2: if len(response) != 2:
raise ANTPError('response has an unexpected number of fields') raise ANTPError('response has an unexpected number of fields')
if 'error' not in response: if 'error' not in response: