Top Level Await in Python like in Deno
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 What do you think ? Share your ideas lets discuss ...
On Sat, Feb 06, 2021 at 10:26:23AM -0000, redradist@gmail.com wrote:
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? -- Steve
I mean to be able to do something like this: ```python import asyncio await asyncio.sleep(1); ```
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
On Sat, 6 Feb 2021 at 07:43, Guido van Rossum
The proposal is to add a default event loop that is always active.
On Sat, Feb 6, 2021 at 06:41
wrote: I mean to be able to do something like this: ```python import asyncio
await asyncio.sleep(1); ```
-- --Guido (mobile) _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/ATXEJR... Code of Conduct: http://python.org/psf/codeofconduct/
It is not the same, it will work in interactive mode .... But I want to run application without interactive mode
On Wed, 24 Mar 2021 at 06:44,
It is not the same, it will work in interactive mode .... But I want to run application without interactive mode _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/O4ME7K... Code of Conduct: http://python.org/psf/codeofconduct/
Sorry - previous reply was sent empty.
So, you probably can do with `asyncio.run`:
```
In [26]: import asyncio
In [27]: asyncio.run(asyncio.sleep(2))
```
https://docs.python.org/3/library/asyncio-task.html#asyncio.run
On Wed, 24 Mar 2021 at 06:44,
It is not the same, it will work in interactive mode .... But I want to run application without interactive mode _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/O4ME7K... Code of Conduct: http://python.org/psf/codeofconduct/
Yes I can, but I am taking about to use it without `asyncio.run` Whenever Python in Top-Level faces with await it will wrap calling all top level statement in async function (for example)
participants (5)
-
Guido van Rossum
-
Joao S. O. Bueno
-
Matthias Bussonnier
-
redradist@gmail.com
-
Steven D'Aprano