I have external events (inotify, etc.) that are collected in one thread and put into a queue for another threat that has to request certain urls generated by these events. Unfortunately the requests.get
even with the timeout
set sometimes pauses indefinitely. I think the server/cloudflare is "blocking" the request and just keeps the connection open...
How can I set a timeout for the requests.get
that stops it execution after a certain time and retries or steps over it?
json_queue = queue.Queue()
def thread1():
while True:
for event in some_external_event:
(url) = event
json_queue.put(url)
def thread2():
while True:
try:
item = json_queue.get()
r = requests.get(url=item, timeout=3)
# DOESNT REACH THIS POINT
json_queue.task_done()
except:
raise #EXCEPTION NEVER GETS RAISED
t1 = threading.Thread(target=thread1)
t1.start()
t2 = threading.Thread(target=thread2)
t2.start()