Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange occasional RuntimeError: Event loop is closed out of nowhere #1155

Open
allefeld opened this issue Oct 4, 2023 · 1 comment
Open

Comments

@allefeld
Copy link

allefeld commented Oct 4, 2023

I'm implementing a kernel by inheriting from ipykernel.kernelbase.Kernel, as described at Making simple Python wrapper kernels.

That generally works well, but I have a strange problem: Occasionally I get an exception RuntimeError: Event loop is closed:

Traceback (most recent call last):
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/site-packages/ipykernel/iostream.py", line 390, in _watch_pipe_fd
    self.write(bts.decode(errors='replace'))
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/site-packages/ipykernel/iostream.py", line 664, in write
    self._schedule_flush()
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/site-packages/ipykernel/iostream.py", line 561, in _schedule_flush
    self.pub_thread.schedule(_schedule_in_thread)
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/site-packages/ipykernel/iostream.py", line 269, in schedule
    f()
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/site-packages/ipykernel/iostream.py", line 559, in _schedule_in_thread
    self._io_loop.call_later(self.flush_interval, self._flush)
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/site-packages/tornado/ioloop.py", line 597, in call_later
    return self.call_at(self.time() + delay, callback, *args, **kwargs)
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/site-packages/tornado/platform/asyncio.py", line 206, in call_at
    return self.asyncio_loop.call_later(
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/asyncio/base_events.py", line 721, in call_later
    timer = self.call_at(self.time() + delay, callback, *args,
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/asyncio/base_events.py", line 732, in call_at
    self._check_closed()
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/asyncio/base_events.py", line 515, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

The traceback does not go back to my code, so I'm not certain whether I did something wrong, or there is a bug in ipykernel.kernelbase? I am unable to reproduce the error, in the exact same situation it sometimes happens and sometimes doesn't.

I found two other issues which mention this exception, but they are about UI events (#825) or parallelization (#534), both of which I do not use. I inherited from ipykernel.kernelbase.Kernel and implemented do_execute, which sends code to an external interpreter and sends its stdout and stderr via self.send_response.

@allefeld
Copy link
Author

allefeld commented Oct 4, 2023

So far I have only encountered the error if using jupyter console --kernel.

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

No branches or pull requests

1 participant