Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: exit gracefully when process started via asyncio is terminated
Currently when process is started through asyncio Runner and it is termited e.g. with SIGINT(ctrl+c) a traceback is printed instead of gracefully exit. Exception ignored in: <function BaseSubprocessTransport.__del__ at 0x7fe980970900> Traceback (most recent call last): File "/usr/lib64/python3.12/asyncio/base_subprocess.py", line 129, in __del__ self.close() File "/usr/lib64/python3.12/asyncio/base_subprocess.py", line 107, in close proto.pipe.close() File "/usr/lib64/python3.12/asyncio/unix_events.py", line 568, in close self._close(None) File "/usr/lib64/python3.12/asyncio/unix_events.py", line 592, in _close self._loop.call_soon(self._call_connection_lost, exc) File "/usr/lib64/python3.12/asyncio/base_events.py", line 793, in call_soon self._check_closed() File "/usr/lib64/python3.12/asyncio/base_events.py", line 540, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed This is caused because asyncio Runner context in asyncio.run is closing the event loop and if exception is unhandled in coroutine(run_command) the transport is not closed before the even loop is closed and we get RuntimeError: Event loop is closed in the transport __del__ function because it's trying to use the closed even loop. Let's catch asyncio.CancelledError in case the process we are trying to read from is terminated, print message, let the asyncio finish and exit gracefully. Closes #13418 Signed-off-by: Frantisek Hrbata <[email protected]>
- Loading branch information