Fix syntax error for throwing a timeout when signal.alarm fires
This commit is contained in:
parent
015fa8ddff
commit
951c315cec
1 changed files with 3 additions and 1 deletions
|
@ -15,6 +15,8 @@ class HTTPTimeoutException(HTTPException):
|
||||||
class HTTPParsingException(HTTPException):
|
class HTTPParsingException(HTTPException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def throw_timeout():
|
||||||
|
raise HTTPTimeoutException()
|
||||||
|
|
||||||
def get_url(url, method="GET", get_params={}, post_data=None, headers={},
|
def get_url(url, method="GET", get_params={}, post_data=None, headers={},
|
||||||
json_data=None, code=False, json=False, soup=False, parser="lxml"):
|
json_data=None, code=False, json=False, soup=False, parser="lxml"):
|
||||||
|
@ -27,7 +29,7 @@ def get_url(url, method="GET", get_params={}, post_data=None, headers={},
|
||||||
if not "User-Agent" in headers:
|
if not "User-Agent" in headers:
|
||||||
headers["User-Agent"] = USER_AGENT
|
headers["User-Agent"] = USER_AGENT
|
||||||
|
|
||||||
signal.signal(signal.SIGALRM, lambda: raise TimeoutError())
|
signal.signal(signal.SIGALRM, throw_timeout)
|
||||||
signal.alarm(5)
|
signal.alarm(5)
|
||||||
try:
|
try:
|
||||||
response = requests.request(
|
response = requests.request(
|
||||||
|
|
Loading…
Reference in a new issue