← Quiz: Threads, Processes and the GIL: all 10 questions
Quiz: Threads, Processes and the GIL · Question 8 of 10
What does this print? (code)
What does this print?
import asyncio
async def job(name, delay):
await asyncio.sleep(delay)
print(name)
async def main():
await asyncio.gather(job("A", 0.2), job("B", 0.1))
asyncio.run(main())
- A.A B
- B.B A
- C.A
- D.B
Answer & explanation
Correct answer: B A
(Each name is printed on its own line.) Both wait at the same time, and B's shorter wait ends first.
Can you get the rest right without peeking?
Take the timed Quiz: Threads, Processes and the GIL quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →