Inside a coroutine you write asyncio.sleep(1) without await. What happens?
Options
- The sleep runs in the background while the coroutine continues
- It creates a coroutine object that never runs, plus a warning (Correct option)
- It blocks the whole event loop for one second, then continues
- Python raises a SyntaxError because
awaitis required there
Answer
A coroutine object is created and never run; Python warns 'coroutine was never awaited'
Why
Calling an async function does not run its code. It only creates a coroutine object, like a recipe that nobody cooks.
The code runs only when you await it or schedule it with asyncio.create_task(...).
Python prints a 'never awaited' warning to help you find this bug.
Remember
Calling an async function returns a coroutine; nothing runs until it is awaited.