Pažljivo pročitaj kod
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.Šta će program ispisati? Napiši ovde: