4 ms·
Doesn't this make await a no-op? In what way are async functions asynchronous if tasks do not run interleaved?
by fluoridation 11mo ago
Doesn't this make await a no-op? In what way are async functions asynchronous if tasks do not run interleaved?
- throwup238 11mo agoTasks are async funcs that have been spawned with asyncio.create_task or similar, which then schedules its execution. A timer of zero doesn't spawn anything so the coroutine just executes in the same frame as the caller so yes it essentially a noop.
- rcxdude 11mo agoThey are async across operations that do 'yield', i.e. when the function eventually runs an i/o operation or sleep or similar. Those are the points where the functions can be interleaved. Simply awaiting another function is _not_ one of those points: await here only means the called function might yield to the scheduler at some point in its execution (it doesn't have to!), not that the calling function will yield immediately.
- fluoridation 11mo agoIsn't asyncio.sleep one of those functions? "other" should be able to appear between "parent before" and "parent after".
- rcxdude 11mo agoYes, but not between "parent before" and "child start" (or between "child end" and "parent after")
- fluoridation 11mo agoAh, OK. That makes sense.