RuntimeError: There is no current event loop in thread 'MainThread'

Open
#929 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
backend

Research direction

Start in ipykernel/inprocess/client.py at the asyncio call shown in the report, then run the failing package tests that reproduce the MainThread error. Determine event-loop handling that works for this path; the issue is done when those tests pass without the RuntimeError.

Written by the indexing model from the issue text.

Description

bug

While trying to update ipykernel's Debian package to 6.13.0, tests were failing with the above error.

I got out of this with:

--- ipykernel.orig/ipykernel/inprocess/client.py
+++ ipykernel/ipykernel/inprocess/client.py
@@ -179,8 +179,7 @@
         stream = kernel.shell_stream
         self.session.send(stream, msg)
         msg_parts = stream.recv_multipart()
-        loop = asyncio.get_event_loop()
-        loop.run_until_complete(kernel.dispatch_shell(msg_parts))
+        asyncio.run(kernel.dispatch_shell(msg_parts))
         idents, reply_msg = self.session.recv(stream, copy=False)
         self.shell_channel.call_handlers_later(reply_msg)

but I'm not sure it's a good solution...

Dominant language
Python
Stars
734
Forks
411
Avg merge
1d 2h
Merged PRs (30d)
9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ipython/ipykernel

All issues in ipython/ipykernel

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.