All quizzesEasy
Coroutines & asyncio.run
Preview — 3 of 10 questions
What is the output of the following code?
javascript
async def greet():
return "hello"
result = greet()
print(type(result))ATypeError: greet() missing required positional argument
B<class 'coroutine'>
Chello
D<class 'function'>
Which statement about asyncio.run() is correct?
Aasyncio.run() can be safely called multiple times, nested inside another already-running event loop, without any issue.
Basyncio.run() runs a coroutine in a background thread while the rest of the program continues immediately.
Casyncio.run(coro()) is the standard, top-level way to execute an async program — it creates a new event loop, runs the given coroutine to completion, and closes the loop.
Dasyncio.run() is only necessary for coroutines that use asyncio.sleep().
Which statement correctly distinguishes await asyncio.sleep(n) from time.sleep(n) inside an async def function?
Aawait asyncio.sleep(n) yields control back to the event loop, allowing other coroutines to run during the wait; time.sleep(n) blocks the entire thread (and therefore the whole event loop), preventing anything else from running during that time.
BBoth functions behave identically inside async code — time.sleep() is just a synonym for asyncio.sleep().
Casyncio.sleep(n) blocks the whole program, while time.sleep(n) only pauses the current coroutine.
Dtime.sleep(n) is the preferred choice for pausing inside async code, since it's simpler and doesn't require await.
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.