Hey IPython developers :) thanks for all your awesome work.
Recently I've been trying out some GUI based workflows in Jupyter, and I've hit some stumbling blocks around asyncio. Where I get deadlocks when trying to wait on Comm
events. As it turns out the kernel will do process one message at a time. Since running a cell creates a message, and waiting for a Comm
depends on a message, the kernel will hang if I try to wait for a Comm in a cell.
I thought the problem would be somewhat intractable, but actually I think it's quite simple to solve. I'm happy to do it myself. I think all I would need to do is to treat Comm
events as a special case that can send asynchronous messages. I think this makes sense, because the other message types are definitely synchronous (like execute_request
); but Comm
events are not. For example, cell execution obviously needs to happen atomically; but should a button click really be blocked by another cell doing an await asyncio.sleep()
?
Happy to do this work myself, as I've spent quite a bit of time figuring out how IPython works. Just wondering what you all think :)
Cool found it :)
Sorry should have searched more. I suppose disperate docs is the side effect of splitting everything up into different concerns.
https://github.com/sonthonaxrk/async_gui_ipython_kernel
I think I've done something kinda cool and opens up some possibilities with IPython.
[I 13:59:36.224 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
kernel b4f40812-cf7d-4f97-925b-84780f946bc9 restarted
Hello, can I embed ipython in an async program? can't seem to find any docs on it. I've tried:
import nest_asyncio
nest_asyncio.apply()
IPython.embed(using='asyncio')
with no luck 😐️
Hello! I'm seeing an issue with my IPython setup on Mac, where attempting to use await
with an async command results in the following error:
648
649 if self._local._loop is None:
--> 650 raise RuntimeError('There is no current event loop in thread %r.'
651 % threading.current_thread().name)
652
RuntimeError: There is no current event loop in thread 'MainThread'.
I've traced it to the fact that the following call always errors out:
import asyncio
asyncio.get_event_loop()
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-6-6908e23590ee> in <module>
----> 1 asyncio.get_event_loop()
/usr/local/Cellar/python@3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/events.py in get_event_loop(self)
648
649 if self._local._loop is None:
--> 650 raise RuntimeError('There is no current event loop in thread %r.'
651 % threading.current_thread().name)
652
RuntimeError: There is no current event loop in thread 'MainThread'.
Python 3.9.7, IPython 7.30.0.
Reproducible test case:
Python 3.9.7 (default, Oct 13 2021, 06:45:31)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.30.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: async def ping():
...: pass
...:
In [2]:
In [2]: await ping()
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/usr/local/lib/python3.9/site-packages/IPython/core/async_helpers.py in __call__(self, coro)
26 import asyncio
27
---> 28 return asyncio.get_event_loop().run_until_complete(coro)
29
30 def __str__(self):
/usr/local/Cellar/python@3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/events.py in get_event_loop(self)
644
645 if self._local._loop is None:
--> 646 raise RuntimeError('There is no current event loop in thread %r.'
647 % threading.current_thread().name)
648
RuntimeError: There is no current event loop in thread 'MainThread'.
In [2]: