diff --git a/ipykernel/iostream.py b/ipykernel/iostream.py index 74e65e4d..87834e26 100644 --- a/ipykernel/iostream.py +++ b/ipykernel/iostream.py @@ -95,10 +95,11 @@ def _start_event_gc(): async def _cancel(): self._event_pipe_gc_task.cancel() # type:ignore - try: + if not self._stopped: self.io_loop.run_sync(_cancel) - except TimeoutError: - pass + else: + self._event_pipe_gc_task.cancel() + self.io_loop.close(all_fds=True) def _setup_event_pipe(self):