[Python-ideas] Top Level Await in Python like in Deno
54 views
Skip to first unread message
redr...@gmail.com
unread,
Feb 6, 2021, 5:27:31 AM2/6/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to python...@python.org
Hi all,
Deno is JavaScript runtime that has very nice feature like Top Level Await, I think it would be also nice to have such feature in Python, it will make using async/await more convenient
> Deno is JavaScript runtime that has very nice feature like Top Level
> Await, I think it would be also nice to have such feature in Python,
> it will make using async/await more convenient
>
> What do you think ? Share your ideas lets discuss ...
I don't know what to think because I don't know what "top level await"
means to you. Can you show an example of what it would look like, how
you would use it, and *why* you would use it?
Can you show a simple example of a task that would be better with top
level await, and why it is better?
I mean to be able to do something like this:
```python
import asyncio
await asyncio.sleep(1);
```
--
--Guido (mobile)
Matthias Bussonnier
unread,
Feb 6, 2021, 1:02:58 PM2/6/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Guido van Rossum, redr...@gmail.com, python-ideas
If it's for the REPL, it's already there, you simply need to start the
async REPL.
$ python -m asyncio
asyncio REPL 3.8.5 | packaged by conda-forge | (default, Sep 16 2020, 17:43:11)
[Clang 10.0.1 ] on darwin
Use "await" directly instead of "asyncio.run()".
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> await asyncio.sleep(1)
>>>
compile and exec have a mode to allow top-level async as well if you
want it programmatically, then you can `await` your code object.
--
Ma
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to python-ideas
I like this idea. It's already the default behavior of the IPython shell, and it would allow for easy scripting with async libraries. I think importing the asyncio module at the top level should do what Guido said, by adding a default event loop that's always active.