-
Notifications
You must be signed in to change notification settings - Fork 55
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: always run a coroutine and work with tornado #71
fix: always run a coroutine and work with tornado #71
Conversation
7a3b4ce
to
404ce8b
Compare
nbclient/util.py
Outdated
check_ipython() | ||
import nest_asyncio | ||
nest_asyncio.apply() | ||
check_patch_tornado() |
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.
We might want to do that only once if we had a loop, not at each coroutine execution?
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.
Well, the patch is not applied when tornado is not imported (this happens in vaex, where I first call this function, then start the server, and call this function again). Also the patch is only applied once (it checks if the Future is in the set).
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.
OK, but what about check_ipython()
and nest_asyncio.apply()
?
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.
For check_ipython the same holds (it can be imported later on), and nest_asyncio has a check build in, in the end, simplicity, otherwise we need to check things that nest_asyncio already checks.
Awesome work @maartenbreddels! |
My problem with this PR is that I don't have a test, I have trouble reproducing the original issue. So lets put it to draft first. |
afd8113
to
88beb2f
Compare
Using the private API |
Thanks a lot for the tests and the awesome work! |
09ce53f
to
a79ae70
Compare
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.
LGTM, let's give it a try. I am about to pop out an alpha 0.4 release for folks to try some of the recently merged changes this week anyway.
0.4.0a0 is released fyi |
This is a port of what I use in vaex
This has been running for quite a while on CI, and seems pretty solid. If an event loop is present it will patch it with nested-asyncio and will also patch tornado, which should solve:
nest_asyncio=True
inNotebookClient.execute
and such methods. nteract/papermill#490Alternative to #67
See also erdewit/nest_asyncio#23 and tornadoweb/tornado#2753
This also checks to see if it is being run in an IPython context (I'm not sure the check makes sense, I just check if it is imported), and will give an error if not v7+, otherwise cells in a notebook may run out of order (a known? issue with older versions of IPython I believe), see also erdewit/nest_asyncio#9