use utils.deadline() in utils.http.request, not raw sigalrm

This commit is contained in:
jesopo 2019-09-02 15:50:21 +01:00
parent d42d694e64
commit b7b2f31c1c

View file

@ -73,8 +73,7 @@ def request(url: str, method: str="GET", get_params: dict={},
if not "User-Agent" in headers:
headers["User-Agent"] = USER_AGENT
signal.signal(signal.SIGALRM, lambda _1, _2: throw_timeout())
signal.alarm(5)
with utils.deadline(seconds=5):
try:
response = requests.request(
method.upper(),
@ -87,10 +86,8 @@ def request(url: str, method: str="GET", get_params: dict={},
stream=True
)
response_content = response.raw.read(RESPONSE_MAX, decode_content=True)
except TimeoutError:
except DeadlineExceededException:
raise HTTPTimeoutException()
finally:
signal.signal(signal.SIGALRM, signal.SIG_IGN)
response_headers = utils.CaseInsensitiveDict(dict(response.headers))
content_type = response.headers.get("Content-Type", "").split(";", 1)[0]