Μετάβαση στο κύριο περιεχόμενο
🔒 Λειτουργία προεπισκόπησης. Τα πρώτα δεκαπέντε μαθήματα Foundations είναι δωρεάν· αυτό είναι Pro. Ξεκινήστε ένα 7ήμερο trial για να ξεκλειδώσετε τον επεξεργαστή, τις υποδείξεις AI και το υπόλοιπο του προγράμματος. Απαιτείται κάρτα, ακυρώνετε οποιαδήποτε στιγμή από το Dashboard.Ξεκινήστε 7ήμερο trial →
← ΜαθήματαSenior Deep-DivesΕνότητα 1 · Concurrency & Async Internalsasyncio: βρόχος γεγονότος βαθιά κατάδυσηpredict3 / 161
+100 XP
Εργασία🌐 shown in EN
📝 **Task:** Predict the 5-line interleave from `asyncio.gather(fetch('A', 1), fetch('B', 2))`. Both fetches print 'start NAME' first, then 'done NAME' after their await — and gather prints the result list last. 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.
Πρόβλεψε έξοδο

Διάβασε τον κώδικα προσεκτικά

import asyncio

async def fetch(name, delay):
    print(f"start {name}")
    await asyncio.sleep(delay)
    print(f"done {name}")
    return name

async def main():
    results = await asyncio.gather(
        fetch("A", 1),   # sleeps 1 s
        fetch("B", 2),   # sleeps 2 s
    )
    print(results)

asyncio.run(main())

# What does this print? Type your prediction.
# Hint: both fetches enter immediately (gather schedules them
# together). A finishes first (shorter sleep). The list at the end
# matches the ORDER the tasks were passed to gather, NOT the
# completion order.

Τι θα εμφανίσει το πρόγραμμα; Γράψε εδώ: