🎙 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 5 of 10

What does this print? (code)

What does this print?

from concurrent.futures import ThreadPoolExecutor
import time

def work(n):
    time.sleep(0.05 * (3 - n))
    return n * 10

with ThreadPoolExecutor() as pool:
    print(list(pool.map(work, [0, 1, 2])))
  1. A.[20, 10, 0]
  2. B.[0, 10, 20]
  3. C.[0, 1, 2]
  4. D.The order changes on every run
Answer & explanation

Correct answer: [0, 10, 20]

map returns results in the order of the inputs, even though task 2 finishes 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 →