Zum Hauptinhalt springen
🔒 Vorschaumodus. Die ersten fünfzehn Foundations-Lektionen sind kostenlos; diese hier ist Pro. Starte einen 7-Tage-Trial, um den Editor, AI-Hinweise und den Rest des Lehrplans freizuschalten. Karte erforderlich, jederzeit im Dashboard kündbar.7-Tage-Trial starten →
← KurseSenior Deep-DivesModul 1 · Parallelität und asynchrone Internaconcurrent.futures vs. Asyncio vs. Threadingpredict9 / 161
+125 XP
Aufgabe
📝 **Aufgabe:** Sagen Sie das 4-Zeilen-Urteil des Pickers voraus – ein Urteil pro Arbeitslast. 📋 Implementieren Sie die obige Funktion. Tests laufen automatisch ab. 💡 **Hinweis:** Lesen Sie die Theorie noch einmal, wenn Sie nicht weiterkommen.
Sage die Ausgabe vorher

Lies den Code sorgfältig

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.

Was wird das Programm ausgeben? Schreib hier:

💬 Diskussion

Sei der erste — stelle eine Frage oder teile einen Tipp.
Anmelden um an der Diskussion teilzunehmen. Lesen ist kostenlos.
Diskussion wird geladen…