import asyncio
async def child():
print("child start")
await asyncio.sleep(0)
print("child end")
async def parent():
print("parent before")
await child() # <-- awaiting a coroutine (not a task)
print("parent after")
async def other():
for _ in range(5):
print("other")
await asyncio.sleep(0)
async def main():
other_task = asyncio.create_task(other())
parent_task = asyncio.create_task(parent())
await asyncio.gather(other_task, parent_task)
asyncio.run(main())
It prints: other
parent before
child start
other
child end
parent after
other
other
other
So the author's point is that "other" can never appear in-between "parent before" and "child start".
You're right, the equivalent JS script produces the same sequence of outputs.
It turns out there is a way to emulate Python's asyncio.create_task().
Python:
JavaScript: