🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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())
  1. A.A B
  2. B.B A
  3. C.A
  4. 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 →