-
Notifications
You must be signed in to change notification settings - Fork 283
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
AsyncKernelClient.is_alive() returns non-awaited coroutine? #621
Comments
Hi @davidbrochart - I've been following the discussion on nbclient and, until now, didn't realize the
I totally agree. I was surprised to see this in nbclient a few months back. I'm not really following how 3 can return a coroutine (awaited or otherwise) and the same goes for 2 unless there's a subclass of A refactoring of AsyncKernelClient.is_alive() that cuts out some of the duplication could be: async def is_alive(self):
"""Is the kernel process still running?"""
from ..manager import AsyncKernelManager
if isinstance(self.parent, AsyncKernelManager):
return await self.parent.is_alive()
return super().is_alive() # defer to KernelClient or perhaps testing if |
Hi Kevin, I'm not sure 2. or 3. are returning a coroutine indeed, maybe you're right they can never do so, it's just that looking at the code it is not obvious, and making any change in this code base requires such a deep knowledge of how everything works that this is becoming complicated. Having type annotations would help us get some certitudes about what's going on, and maybe fix bugs or refactor. |
I totally agree and have found this exercise helpful in other projects. |
async is_alive() can return:
AsyncKernelManager
.KernelManager
which is notAsyncKernelManager
.Cases 1. and 4. are fine, but 2. and 3. could potentially return a non-awaited coroutine. This is causing problems e.g. in jupyter/nbclient#138, but I think the main issue is that we don't know the objects that we are manipulating any more, because we are trying to have a single code base that works for async and non-async. I also think that we are allowing for too much freedom, for instance mixing a non async kernel manager and an async kernel client. This is becoming too complicated.
I think adding type annotations, as @MSeal suggested in #553, will help us understand and improve the situation.
The text was updated successfully, but these errors were encountered: