Bird
0
0

Given the code snippet below, what will be the output?

medium📝 Predict Output Q13 of 15
Selenium Python - CI/CD Integration
Given the code snippet below, what will be the output?
from concurrent.futures import ThreadPoolExecutor
import time

def test_func(name):
    time.sleep(1)
    return f"Test {name} done"

with ThreadPoolExecutor(max_workers=3) as executor:
    results = list(executor.map(test_func, ['A', 'B', 'C', 'D']))
print(results)
AError due to max_workers less than tasks
B['Test A done', 'Test B done', 'Test C done']
C['Test A done', 'Test B done', 'Test C done', 'Test D done']
D['Test D done']
Step-by-Step Solution
Solution:
  1. Step 1: Understand ThreadPoolExecutor with max_workers=3

    It runs up to 3 threads at once, but can handle more tasks by queuing them.
  2. Step 2: Analyze executor.map behavior

    executor.map runs test_func on all 4 inputs and returns results in order after all finish.
  3. Final Answer:

    ['Test A done', 'Test B done', 'Test C done', 'Test D done'] -> Option C
  4. Quick Check:

    All tasks run, results list includes all [OK]
Quick Trick: ThreadPoolExecutor queues extra tasks beyond max_workers [OK]
Common Mistakes:
  • Assuming only 3 results because max_workers=3
  • Expecting error due to more tasks than workers
  • Thinking results order changes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes