Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesSenior Deep-DivesModule 1 · Concurrency & Async Internalsconcurrent.futures vs asyncio vs threadingpredict9 / 161
+125 XP
Task
📝 **Task:** Predict the 4-line verdict from the picker — one verdict per workload. 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.
Predict the output

Read the code carefully

def pick(workload):
    """workload = dict with keys: kind ('io' or 'cpu'),
                                  has_async_lib (bool),
                                  is_numpy_heavy (bool)."""
    if workload["kind"] == "io":
        if workload["has_async_lib"]:
            return "asyncio"
        return "threads"
    # CPU-bound
    if workload["is_numpy_heavy"]:
        return "stay-single"
    return "multiprocessing"

cases = [
    # Async HTTP client (aiohttp / httpx) — io + async lib available
    {"kind": "io",  "has_async_lib": True,  "is_numpy_heavy": False},
    # Legacy sync requests + 100 calls — io but no async lib
    {"kind": "io",  "has_async_lib": False, "is_numpy_heavy": False},
    # NumPy matrix multiply — cpu but C-extension releases GIL
    {"kind": "cpu", "has_async_lib": False, "is_numpy_heavy": True},
    # Pure-Python combinatorial search — cpu, all Python
    {"kind": "cpu", "has_async_lib": False, "is_numpy_heavy": False},
]

for c in cases:
    print(pick(c))

# What does this print? Type your prediction.

What will the program print? Write here:

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…