Naar hoofdinhoud
🔒 Voorbeeldmodus. De eerste vijftien Foundations-lessen zijn gratis; deze is Pro. Start een 7-daagse trial om de editor, AI-hints en de rest van het curriculum te ontgrendelen. Kaart vereist, op elk moment opzegbaar in Dashboard.Start 7-daagse trial →
← CursussenSenior Deep-DivesModule 1 · Gelijktijdigheid en asynchrone interne processenconcurrent.futures versus asyncio versus threadingpredict9 / 161
+125 XP
Opdracht
📝 **Taak:** Voorspel het oordeel van de kiezer in vier regels: één oordeel per werklast. 📋 Implementeer bovenstaande functie. Tests worden automatisch uitgevoerd. 💡 **Hint:** Herlees de theorie als je vastloopt.
Voorspel uitvoer

Lees de code zorgvuldig

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.

Wat zal het programma uitprinten? Schrijf hier:

💬 Discussie

Wees de eerste — stel een vraag of deel een tip.
Log in om mee te doen aan de discussie. Lezen is gratis.
Discussie laden…