tkp-archive/pyEX

not possible to exit SSE in a non-async mode

Closed this issue · 1 comments

The SSEClient invokes self._connect() while handling the requests.RequestException error, so that it is not possible to stop streaming.

Steps to reproduce the behavior:

def on_data(d):
    print(f'{datetime.now()} on_data {len(d)=}')

event = Event()
iex_api.streaming.stocksUSNoUTP1SecondSSE(symbols=tickers, on_data=on_data, exit=event)
time.sleep(1)
event.set()
print('Event set')
time.sleep(100)
2021-05-27 **20:43:39**.421475 on_data len(d)=1
Event set
2021-05-27 **20:43:44**.156520 on_data len(d)=1

Expected behavior
after event.set() the underlying connection should be closed forever

This is a known issue:
psf/requests#5372

I will see if I can work around it