In "The Python Language Reference, Release 3.13.0a0",
there is this section:
|6.4 Await expression
|
|Suspend the execution of coroutine on an awaitable object.
|Can only be used inside a coroutine function.
|
|await_expr ::= "await" primary
|
|New in version 3.5.
. And this is the whole section.
What I do not understand:
- Which coroutine is suspended?
- Which object is the object mentioned?
- For what purpose is the value of the primary expression used?
- What does it mean to "suspend something on something"?
We say that an object is an awaitable object if it can be used in an
await expression. Many asyncio APIs are designed to accept awaitables.
There are three main types of awaitable objects:
coroutines, Tasks, and Futures.
Stefan Ram schrieb:
In "The Python Language Reference, Release 3.13.0a0",
there is this section:
|6.4 Await expression
|
|Suspend the execution of coroutine on an awaitable object.
|Can only be used inside a coroutine function.
|
|await_expr ::= "await" primary
|
|New in version 3.5.
. And this is the whole section.
What I do not understand:
- Which coroutine is suspended?
- Which object is the object mentioned?
- For what purpose is the value of the primary expression used?
- What does it mean to "suspend something on something"?
In "The Python Language Reference, Release 3.13.0a0",
there is this section:
|6.4 Await expression |
|Suspend the execution of coroutine on an awaitable object.
|Can only be used inside a coroutine function.
|
|await_expr ::= "await" primary |
|New in version 3.5.
. And this is the whole section.
What I do not understand:
- Which coroutine is suspended?
- Which object is the object mentioned?
- For what purpose is the value of the primary expression used?
- What does it mean to "suspend something on something"?
On 26 Jan 2024 18:36:50 GMT, Stefan Ram wrote:...
In "The Python Language Reference, Release 3.13.0a0",
there is this section:
|6.4 Await expression |
|Suspend the execution of coroutine on an awaitable object.
|Can only be used inside a coroutine function.
|await_expr ::= "await" primary |
- What does it mean to "suspend something on something"?It returns control to the point of execution of the .send method that >(directly or indirectly) started or resumed the coroutine execution.
But your explanation seems to have no mention of the "something" /
"the awaitable object" part following the preposition "on". Shouldn't
this awaitable object play a rôle in the explanation of what happens?
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
- Which object is the object mentioned?
The result returned from the primary.
- For what purpose is the value of the primary expression used?
To return the awaitable object.
But your explanation seems to have no mention of the "something" /
"the awaitable object" part following the preposition "on". Shouldn't
this awaitable object play a rôle in the explanation of what happens?
On 27/01/24 10:46 am, Stefan Ram wrote:
But your explanation seems to have no mention of the "something" /
"the awaitable object" part following the preposition "on". Shouldn't
this awaitable object play a rle in the explanation of what happens?
If it helps at all, you can think of an async function as being very
similar to a generator, and "await" as being very similar to "yield
from". In the current implementation they're almost exactly the same
thing underneath.
You can explain a function call without saying much about the called function. >Similarly, you can explain "await <expr>" without saying much about
"<expr>".
I think that the author of the specification could improve the
specification by addressing my questions from the OP,
but I am not able to submit a suggestion for a wording myself, because I
am still learning asyncio.
It can be a tricky thing to get to grips with, particularly if you are
trying to understand how it works at a low level.
Does "await f()" (immediately) call "f()"?
|await_expr ::= "await" primary
|Suspend the execution of coroutine on an awaitable object.
My ideas of language specifications are that they should contain all
the information to write an implementation of the language. I am not
sure whether the Python Language Reference already fullfils this
criterion.
def f(): return g()
async def f(): return await g()
In "The Python Language Reference, Release 3.13.0a0",
there is this section:
|6.4 Await expression
|Suspend the execution of coroutine on an awaitable object.
|Can only be used inside a coroutine function.
|await_expr ::= "await" primary
Heck, even of the respected members of this newsgroup, IIRC, no one
mentioned "__await__". So, let's give a big shoutout to Victor!
(Then, it should also be interesting to understand how asyncio
uses "await" to implement asynchronous I/O.)
Heck, even of the respected members of this newsgroup, IIRC, no one
mentioned "__await__".
On 1 Feb 2024 10:09:10 GMT, Stefan Ram wrote:
Heck, even of the respected members of this newsgroup, IIRC, no one
mentioned "__await__".
It’s part of the definition of an “awaitable”, if you had looked that up.
<https://docs.python.org/3/glossary.html#term-awaitable>
So, this is how the control is transferred to the event
loop after an "await sleep"! Initially, the control goes
to "sleep", but this transfers the control to the event loop
(until "sleep" stops waiting for its future in "await future").
|The IO part of the event loop is built upon a single crucial
|function called "select".
I am still waiting for async files in the
style of nodejs that works on windows and
is bundled with the main python distribution.
I am not very fond on doing something
like adding listeners to a file descriptor,
in nodejs async files are based on callbacks
not on listeners. Whats the roadmap here?
Lawrence D'Oliveiro schrieb:
On 2 Feb 2024 09:12:06 GMT, Stefan Ram wrote:
|The IO part of the event loop is built upon a single crucial
|function called "select".
select(2) has limitations. Better to use poll(2). Depending on *nix
variant, other more advanced alternatives may also be available
<https://docs.python.org/3/library/select.html>.
On 2 Feb 2024 09:12:06 GMT, Stefan Ram wrote:
|The IO part of the event loop is built upon a single crucial
|function called "select".
select(2) has limitations. Better to use poll(2). Depending on *nix
variant, other more advanced alternatives may also be available <https://docs.python.org/3/library/select.html>.
... that works on windows ...
On Sat, 3 Feb 2024 00:45:18 +0100, Mild Shock wrote:
... that works on windows ...
You lost me there.
The docu tells me:
Windows
loop.add_reader() and loop.add_writer() only accept
socket handles (e.g. pipe file descriptors are not supported). https://docs.python.org/3/library/asyncio-platforms.html
Alternatives are aiofiles and anyio and maybe more,
but not sure whether they span all platforms, i.e. unix,
windows and mac or whether they have similar restrictions.
Theoretically on Windows IOCP should also cover file handles: https://en.wikipedia.org/wiki/Input/output_completion_port
Its use by libuv the basis for node.js.
Lawrence D'Oliveiro schrieb:
On Sat, 3 Feb 2024 00:45:18 +0100, Mild Shock wrote:
... that works on windows ...
You lost me there.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 54:12:20 |
Calls: | 10,397 |
Calls today: | 5 |
Files: | 14,067 |
Messages: | 6,417,409 |
Posted today: | 1 |