I've seen examples of such code working in certain environments (eg https://github.com/ipython/ipykernel/pull/323).
But for me this only raises SyntaxError
so far:
Update:
I know that in "pure" python it won't work and await
is supposed to be used in async def
's only.
I also know that in jupyter it is possible (see link above) so the engine is capable of doing this. The question is how to get rid of this error message.
Update2 What's the idea of calling await directly:
I'm working with an async library. In current version of jupyter it's hard to get the return value of a coroutine:
The best thing I've come up to is through global variables:
One of the problems here is that res
is not ready in the cell 25 yet. I have to wait until I see "done", then use the value in the another cell.
Another problem is semantic asymmetry between calling a coroutine from the cell directly and from another coroutine, which is pretty irrelevant when writing scripts in an editor, but quite crucial for repl.
Now consider this:
Got it!
This needs development version of IPython to be installed (https://github.com/ipython/ipython/pull/11155).
Which is:
pip install git+https://github.com/minrk/ipython.git@more-await-repl#egg=ipython
pip install git+https://github.com/minrk/ipykernel.git@run-async#egg=ipykernel
Update:
As noted by @ack, nowadays this functionality is present in the latest version ipykernel on pypi.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With