Commit 6b63ca42 authored by Bengfort's avatar Bengfort
Browse files

timeout on request

parent 4ad99340
Pipeline #11866 passed with stages
in 2 minutes and 17 seconds
......@@ -18,6 +18,7 @@
import json
import os
import selectors
import uuid
from contextlib import contextmanager
from pathlib import Path
......@@ -38,6 +39,13 @@ def create_fifo(path):
def raise_on_timeout(fh, timeout):
with selectors.DefaultSelector() as sel:
sel.register(fh, selectors.EVENT_READ)
if fh not in
raise TimeoutError
def send(path, data):
if not os.path.exists(path):
raise FileNotFoundError(path)
......@@ -47,10 +55,11 @@ def send(path, data):
return fh.write(bdata)
def request(data):
def request(data, timeout=10):
_id = str(uuid.uuid4())
with create_fifo(get_path(_id)) as fh:
send(get_path('request'), (_id, data))
raise_on_timeout(fh, timeout)
return json.loads(fh.readline())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment