Skip to content

Comments

Close websocket connection before asyncio.run() terminates#315

Open
yubiuser wants to merge 1 commit intopytr-org:masterfrom
yubiuser:fix/asyncio
Open

Close websocket connection before asyncio.run() terminates#315
yubiuser wants to merge 1 commit intopytr-org:masterfrom
yubiuser:fix/asyncio

Conversation

@yubiuser
Copy link
Contributor

I've noticed that the websocket connection is not properly closed before asyncio.run() terminates. This resulted in the following error

10:27:07 Nothing to download.
Fatal error on SSL transport
protocol: <asyncio.sslproto.SSLProtocol object at 0x722be3ff6c20>
transport: <_SelectorSocketTransport closing fd=9>
Traceback (most recent call last):
  File "asyncio/selector_events.py", line 924, in write
OSError: [Errno 9] Bad file descriptor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "asyncio/sslproto.py", line 690, in _process_write_backlog
  File "asyncio/selector_events.py", line 930, in write
  File "asyncio/selector_events.py", line 725, in _fatal_error
  File "asyncio/selector_events.py", line 737, in _force_close
  File "asyncio/base_events.py", line 753, in call_soon
  File "asyncio/base_events.py", line 515, in _check_closed
RuntimeError: Event loop is closed

This PR added async def close() method to TradeRepublicApi in api.py that gracefully closes the websocket. The new method is now used at the end of each async loop.

Now it shuts down without error.

Signed-off-by: yubiuser <github@yubiuser.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant