-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Jupyter notebook & lab kernel restarting without obvious reason when working with Jina #5863
Comments
this is most likely an ipykernel/ipython issue, not a notebook one, as the
kernel is running in a different process altogether. You could try asking
over there!
https://github.com/ipython
Anyhow; Before you import your code, Ipykernel has already started (and
potentially tweaked) the main asyncio event loop in its process, and its
lifecycle is tied to that. I see your code is not being awaited. If your
code ever stops the loop, it will stop the kernel.... patterns like
"run_until_completed" _might_ work, as might some other mechanism, e.g
threads, dask.
However, you'd get the same behavior in any other cooperative async
program, e.g. fastapi, django3.
https://ipython.readthedocs.io/en/stable/interactive/autoawait.html
Unfortunately: we've probably not going to be able to change anything to
suit your specific library.
To keep on top of this, I recommend checking in and running some demo
notebooks during CI with nbconvert:
https://nbconvert.readthedocs.io/en/latest/execute_api.html
Notebooks also make great documentation, and your users can use them
without downloading anything on a number of services, like mybinder.org.
|
i see! Thank you @bollwyvl for pointing me to the right direction. Now I look carefully at our log again, it does use builtin
That should be the indicator of this problem. This link you sent looks pretty relevant: https://ipython.readthedocs.io/en/stable/interactive/autoawait.html |
after some dig in, i think this is most related to ipykernel. similar issue reported here ipython/ipykernel#548 |
We have refactored the asyncio ops (jina-ai/serve#1450) on our end, this issue is solved. The main idea is, jupyter already has a running eventloop in the beginning. Do not try to terminate/stop that event loop. Use |
Hi Jupyter team, I'm the maintainer of the Jina project. I recently found out our project does not play well with Jupyter notebook (6.1.5), not only that but also Jupyter lab (2.2.6), your official online lab, inside Docker (
jupyter/minimal-notebook
), macOS & Linux. I think it is safe to say Jina and Jupyter are not compatible and as the maintainer I really want to figure out why.Reproduce the Kernel Restart
Here is how to reproduce the result in Notebook/Lab (with Python 3.7 & 3.8 Kernel), zipped notebook is attached. Interestingly, the below code snippet works completely fine in Python, IPython, it just fails under Notebook/Lab of any kind:
💥 💥 💥 💥 Kernel gets restarted at now for no obvious reason after the last cell.
With
--debug
it just says:Now the line below will complain about
f is undefined
because the kernel is restartedReasons?
Unfortunately, from the Jupyter debug log and Chrome dev console, I can't find much useful information on why the kernel is restarted? Who triggers it?
Resource-wise, the above code snippet is pretty standard, no memory-eating or strong computational demanding.
Conflict Tech Stack?
Jina does not have many dependencies, they are
We heavily rely on ZeroMQ which as far as I know is also the communication stack behind Jupyter. Could this be the problem? We also heavily rely on
multiprocessing
andasycio
.uvloop
looks suspicious at first, but removinguvloop
did not help.Other Attempts
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
No luck here.
Shed a Light?
I know this may beyond Jupyter itself. But as the maintainer of Jina I really want to figure out the reason behind the crash. With my limit understanding on how Jupyter works, that's the best I can try for now. Maybe some insight and guess from you? It would be really awesome! ❤️
If you need any elaboration on the problem, I'm here! 👋
jina-jupyter-bug-report.ipynb.zip
The text was updated successfully, but these errors were encountered: