unpythonic
unpythonic copied to clipboard
Help wanted for testing async support
Help wanted!
The interaction between unpythonic and the async stuff that was added in Python 3.5 is totally untested, because I haven't used, and I'm not even that familiar with, that part of Python myself.
Reading Brett Cannon's explanation, I surmise the async features are intended mainly for "microthreading" typical server loads, which mostly wait on I/O, but must scale to thousands of simultaneous requests. Coming from numerical background where the load is practically always CPU- or memory-bound, I haven't found much use for such constructs, since there the GIL makes them uninteresting. Multiprocessing, Cython + OpenMP, or MPI, exactly one task per core, done.
So, discussion and test cases are more than welcome!
If interested, please post a comment here, or open a PR if you have some tests you'd like to suggest. See directories unpythonic/test and unpythonic/syntax/test for examples. (Any test modules in these directories are autodetected by runtests.py.)
Note that I have absolutely no idea in which kind of use cases unpythonic and async would appear together - that is exactly why this is help wanted.
If you have such a use case and especially if it doesn't work, please share!
(As of 0.14.1, the current level of async support in unpythonic is a blind guess. The macros recognize the AST nodes for the async stuff, but since I'm not quite sure what should be done with them, they try to do something similar as to the same "basic" (no async) node. Needless to say, there are probably bugs.)
Linking to the relevant PEP. Maybe this one too.
Having done some frontend coding in the meantime, I now have a fairly good understanding of what async/await do, but this is not a high priority for unpythonic. Help is still welcome.
On the topic of async concurrency, Trio looks interesting. See also the original blog post on Trio by its author, Nathaniel Smith.
- At least
continuationsneeds anawaitwhen it calls into the continuation it extracted, if the continuation is an async function. - Also tail calls into async continuations should be
awaited. This may be difficult to do, since we don't currently keep track of the type of each function (and sometimes this information is not lexically available).- Maybe add a runtime wrapper:
return await f(...) if iscoroutine(f) else f(...).
- Maybe add a runtime wrapper: