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
Make a pyproxy of an awaitable python object an awaitable javascript object #1170
Conversation
Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
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.
Thanks @hoodmane ! A few minor comments below.
Also
- all tests currently rely on
eval_code_async
, it might be good to add a test that manually generates an awaitable object with run in Python, and passes it to JS. - could you please test that in JS the
then
method is defined only if the Python object is awaitable. - please remove the warning from https://github.com/iodide-project/pyodide/blob/1aea60d91db6dc55cf7108b3f8ddf3c7049af0ff/src/pyodide-py/pyodide/_base.py#L319
- Switched from ̀Jedi to rlcompleter for completion in | ||
`pyodide.console.InteractiveConsole` and so in `console.html`. This fixes | ||
some completion issues (see | ||
[#821](https://github.com/iodide-project/pyodide/issues/821) and | ||
[#1160](https://github.com/iodide-project/pyodide/issues/821) | ||
[#1160](https://github.com/iodide-project/pyodide/issues/1160) |
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.
I think we should re-organize it by submodule as we did for the last release as now it's getting a bit difficult to find things. No action needed in this PR.
@rth I think I addressed all the comments in your review. |
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.
A minor formatting comment otherwise looks good. Thanks!
This PR together with #1158 together finish async/await support. I merged #1158 here even though the change sets are independent because some sort of event loop is necessary in order to test this PR.
This implements
await
onpyproxy
whenever thepyproxy
is awaitable. It uses_PyCoro_GetAwaitableIter
to check whether the object is awaitable just like in theGET_AWAITABLE
opcode. Normally in implementing theawait
keyword in Python, Python would next use theYIELD_FROM
command, but this assumes that Python is yielding into an enclosing coroutine. Instead we useasyncio.ensure_future
to schedule the awaitable if necessary and wrap in a future, then we create a promise and connect the promise handles to the future. This could be implemented rather more concisely in Python rather than C but the current bootstrapping scheme makes using Python code to implement PyProxy a bit annoying.This mirrors the semantics of the underlying python awaitable, so if it is a coroutine then awaiting it multiple times will raise an error, if it is a future-like object then awaiting multiple times is fine.
The error formatting is a bit limited, these
PythonError
wrappers don't print particularly useful messages in Javascript by default. To improve this requires better javascript / python error integration, something like #1154.