I need to find out a way to smoothly manage server stalls when I have been reading data from it. I wrote the piece of code below:
def listener():
resp = requests.get(someurl, stream=True)
if resp.status_code == 200:
for line in resp.iter_lines():
if line:
do_something_with_the_line
print(result)
price_thread = threading.Thread(target=listener, name="StreamingThread", args=[])
trade_thread.start()
The code works well until a stall of the server occur (the API provider suggests a stall occur when no "lines" are received in 10 seconds).
How can I implement this in my code?
In other words I would try to recall the listener
method without exiting the price_thread
thread when a stall occur.
Thanks in advance