OpenCyphal / pycyphal

Python implementation of the Cyphal protocol stack.
https://pycyphal.readthedocs.io/
MIT License
120 stars 105 forks source link

Worker threads should automatically terminate when the event loop is closed #202

Closed pavel-kirienko closed 2 years ago

pavel-kirienko commented 2 years ago

Currently, we get the following messages in the logs occasionally during process termination:

2022-01-06 18:31:33 deep-thought pyuavcan.transport.can.media.socketcan._socketcan[245385] ERROR SocketCANMedia('slcan1', mtu=8) thread failure: Event loop is closed
Traceback (most recent call last):
  File ".../lib/python3.10/site-packages/pyuavcan/transport/can/media/socketcan/_socketcan.py", line 182, in _thread_function
    loop.call_soon_threadsafe(handler_wrapper, frames)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 790, in call_soon_threadsafe
    self._check_closed()
  File "/usr/lib/python3.10/asyncio/base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed