-
Notifications
You must be signed in to change notification settings - Fork 284
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
Fix shutdown and cleanup behavior #772
Conversation
This is now working well in conjunction with jupyter-server/jupyter_server#792. Note that the downstream |
This actually breaks |
Okay, this now works for all the test cases:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes look good to me - thank you @blink1073!
I confirmed that the noise following the exit of jupyter qtconsole
when 7.2.2 is used is now completely silent.
@ccordoba12 or @mrclary - are either of you able to take this for a spin as well? (Thanks for the great reproduction scenario!)
@kevin-bates @blink1073, thanks for the quick updates! The baseline:
produces the errors that I reported on shutdown. Then using https://github.com/blink1073/jupyter_client/tree/fix-shutdown-behavior
does not produce the errors on shutdown. |
Cool, let's give it a go. |
@blink1073 I might be wrong, but I think this causes nbclient leaking I've tried fixing it by stopping the loop in jupyter/nbclient#237, but jupyter_client/jupyter_client/utils.py Line 18 in 3697a0d
I'm interested in why the method doesn't create a new loop every time there's no running loop? try:
loop = asyncio.get_running_loop()
except RuntimeError:
# Workaround for bugs.python.org/issue39529.
#try:
# loop = asyncio.get_event_loop_policy().get_event_loop()
#except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop) I'd be quite happy to fix the issue, but I think I need a bit more context to understand what's expected from |
Hi @mariokostelac, I'd be concerned about another part of the application having a handle on a non-running loop. I think maybe we need to check if the loop returned by |
@blink1073 any chance you can explain this a bit more? Do you think that stopping and closing the loop in the linked PR is problematic? If we don't do it, we definitely leak open loops, and consequently, To be transparent upfront, I'm no expert on async subsytem in python, so take everything with a grain of salt. jupyter_client/jupyter_client/utils.py Line 18 in 3697a0d
jupyter_client/jupyter_client/utils.py Line 14 in 3697a0d
If there's no running loop, we need some loop to run our coroutine. New loop seems perfectly reasonable to me, but we go further, and go straight to the event policy (to avoid the deprecation), and risk that we get a loop that's closed already. Why do we do that? Is it to reduce loop creations? Is the problem that nbclient's just_run doesn't go that far to get a loop to run on? Also, what's the expectation from "current loop"? Is the code I've suggested in nbclient lib breaking some contract by stopping and cancelling the loop? |
My concern is if another part of the program has called try:
loop = asyncio.get_running_loop()
except RuntimeError:
try:
loop = asyncio.get_event_loop_policy().get_event_loop()
if loop.is_closed():
loop = asyncio.new_event_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop) |
Hmm, I get your concern. I wonder whether the solution I've suggested in nbclient is actually ok, or it leaves the system in some unexpected state. If latter is the case, we can change jupyter_client to get around it, but some other (unrelated) libraries could break. Is it expected that |
Thanks for the context.
I've left more comments on the nbclient PR. From what I understand, it
makes sense to make run_sync implementations between these two the same,
and then migrate off get_event_loop at the same time.
On Fri 1 Jul 2022 at 16:14, Steven Silvester ***@***.***> wrote:
It isn't clear from the docs
<https://docs.python.org/3/library/asyncio-policy.html#asyncio.AbstractEventLoopPolicy.get_event_loop>.
In any case, the get_event_loop_policy().get_event_loop() was meant to be
deprecated along with asyncio.get_event_loop(), but wasn't in 3.10 due to
an oversight. We'll want to implement #755
<#755> for a proper fix.
—
Reply to this email directly, view it on GitHub
<#772 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOUEC6NNSICXBJEDMPMHVTVR34LPANCNFSM5TTXJJOQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
.mk
|
Fixes #771
Includes improvements made while working on jupyter-server/jupyter_server#792
Also avoids leaving event loops open at exit in a few more places.