A Blocking Call Inside a Coroutine

import asyncio
import time

async def blocking():
    print("blocking start")
    time.sleep(1)
    print("blocking end")

async def quick():
    print("quick start")
    await asyncio.sleep(0.1)
    print("quick end")

async def main():
    await asyncio.gather(blocking(), quick())

asyncio.run(main())

What order do the four print statements appear in?

A

blocking start, quick start, blocking end, quick end. gather interleaves the two coroutines one print statement at a time, in the order they were passed in.

B

blocking start, blocking end, quick start, quick end. time.sleep blocks the whole thread instead of yielding to the event loop, so blocking() runs from start to finish before quick() gets a chance to run at all.

C

blocking start, quick start, quick end, blocking end. asyncio.gather runs both coroutines concurrently regardless of how each one waits, so the event loop still switches to quick() while blocking() is sleeping.

D

quick start, quick end, blocking start, blocking end. asyncio.gather always runs the coroutine with the shorter delay first.