-
Notifications
You must be signed in to change notification settings - Fork 151
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
nbformat asynchronous API? #194
Comments
Great idea. I'm 100% supportive of adding async calls to this library. I'll be unlikely to help with implementation / review, but other folks who have helped make jupyter_client and nbclient async can.
Since 3.5 is no longer supported by Python org (no more security patches as of this month) I think 3.6+ is probably right for next release. Python 3.6 is still getting security patches through 2021, I don't see a reason to drop it yet, especially with some format changes coming that older setups may need to use this to parse.
I'd vote adding an |
Thanks for the thoughts!
Oh, I would not dream of breaking those! And, as presently everything upstream is blocking, I wouldn't even touch them, and in fact have the initial, reference async implementations be wrappers of the existing functions inside an executor, which will require inspection for thread-safety issues, but as is a continuing mystery to me, file io still has no async implementations in stdlib, and should be considered table stakes for this work. One concern... in my initial, very hacked-up PoC, I arrived at something not too dissimilar, but far worse, than
Right. This may warrant its own issue, altogether, or at least a signpost on a roadmap.. Going further, if we are going to 3.6, and to ensure no badness, perhaps a precondition to this work is to start adding typings. A quick run through of the test suite through |
Just use
I don't see it as a requirement to do this work. Let's keep it as a separate issue. And yes traitlets don't play all that nice with type hinting. |
Hi @bollwyvl, are there any updates on this? I have a draft PR open to make |
Sorry, no updates yet, but thanks for the links... looks like there's going to be a flurry of long-overdue CI scut work on various projects due to travis CI changes, so fun feature stuff might be on the back burner for a tick.. If you're feeling |
@bollwyvl no worries. I prefer the proxy option since that requires less code and doc changes, and it'll leave the synchronous methods as is with less chance of causing any problems downstream. |
@mwakaba2 So i've been looking around some at this (still very experimental)... no guarantees it will stay like it is, but might be something to talk about at the nuts-and-bolts layer. I am wondering if To that end, I've been looking into anyio, which seems actively developed, type annotated, and documented, and supports all kinds of handy things on trio, curio, uvloop, and asyncio with the same API. |
Maybe even the bigger question: should This still leaves (potentially) long-running tasks, and these will still be (natively) blocking for the time being, but something like anyio.run_sync_in_worker_thread seems far more consistent than playing whack-a-mole with different types of open file handles, which JSON parsers and validators need to read in their entirety anyway. |
Thanks for sharing the draft PR. Yeah, compared to |
I guess the downside of dropping |
Presumably the next major (or shortly thereafter) release of
nbformat
will be python 3.6+ (or 3.7).Among the other benefits, this will make use of proper
async
andawait
possible, without relying ontornado
to get cooperative behavior with downstreams likenotebook
andjupyter_server
, or embedded in more exotic things.Some places, which are all blocking today, that would likely benefit from being (apparently) asynchronous for certain workloads:
Such workloads would include
nbviewer
nbviewer
does)Developer Experience
Typographically, it could be something like (assuming IPython-like top-level await for demonstration purposes):
param
proxy
or perhaps, with a full mirroring:
prefix
just prefix with
a
Async facade/Configuration
While future asynchronous parsers/validators may arise, given that all of the above APIs are actually implemented as blocking behaviors right now, e.g.
json.load
orjsonschema.validate
, an initial facade would probably be needed, perhaps as aThreadPoolExecutor
, etc. which might require configuration, e.g.NBCONVERT_THREADS
.Testing/Dependencies
pytest-asyncio
is very helpful in verifying async behavioruvloop
,trio
asv
would be very demonstrativeDownstreams
Of course, no downstreams would be ready to use this today! Some coordination might be necessary to determine any other gotchas that might arise, but this also means it can be released as an "experimental" API relatively quickly. As long as the original API remains, basically unchanged, however, there should be no rush-to-implement to catch a compatibility window, even once it is considered "supported".
cc @goanpeca
The text was updated successfully, but these errors were encountered: