Три способа выполнить множество задач с asyncio
Функция для примера:
async def do_it(n):
await asyncio.sleep(random.uniform(0.5, 1))
return n
1. Последовательный вызов
async def main():
for i in range(100):
result = await do_it(i)
Такой вызов имеет смысл только тогда, когда результат одной задачи требуется для вызова следующей.
Если они независимы, то это антипаттерн, так как аналогичен простому синхронному вызову по очереди.
2. Упорядоченный результат
async def main():
tasks = [do_it(i) for i in range(100)]
results = await asyncio.gather(*tasks)
Выполняет корутины конкурентно и возвращает результат в виде списка.
Полезен когда требуется получить результаты в том же порядке в котором задачи отправлены.
3. Результат по мере готовности
tasks = [asyncio.create_task(do_it(i)) for i in range(100)]
for cor in asyncio.as_completed(tasks):
result = await cor
Так же выполняет корутины конкурентно, но не гарантирует порядок. Результат возвращается по мере готовности, каждый отдельно.
Полезен когда нужно обработать любой ответ как можно скорее.
#async
🏴Intensa jornada en el mercado de fichajes de la Premier League:
🇧🇪Sebastian Bornauw (26 años) ficha por el Leeds. El acuerdo con el Wolfsburg y los 'whites' se cierra por cerca de €6M.
🏴El delantero escocés Dan Cummings (19 años) es nuevo refuerzo del West Ham. Llega libre tras terminar contrato con el Celtic.
🇸🇳Habib Diarra (21 años) ficha por el Sunderland. Han pagado casi €32M por el mediocampista al Estrasburgo, lo que lo convierte en el fichaje más caro de la historia de los 'black cats'.
🇳🇱El delantero Zepiqueno Redmond (19 años) llega al Aston Villa como agente libre tras quedar desvinculado del Feyenoord.
@LaGuiadelFutbol | #PremierLeague
⚡️Fanton EN: Premier League Gameweek 35 Overview
#PremierLeague#fantasy
Fanton EN presents a preview of Premier League Gameweek 35, covering key matches like Leicester vs. Southampton, Chelsea vs. Liverpool, Brighton vs. Newcastle, and Crystal Palace vs. Nottingham Forest. Each game carries significant implications for fantasy lineups, with Liverpool, Newcastle, and Nottingham still battling for crucial spots.
Source: link
@tonlines
Manchester City es campeón por 4ta vez consecutiva en la Premier League, luego de vencer 3-1 al West Ham
@Fut_planet⚜️#PremierLeague🏴#City🏴
Title races are rarely decided by headlines alone.
Probability shifts long before the table confirms it.
#ManchesterCity#PremierLeague#EdgeMarket#PredictionMarkets
Después de una temporada dónde veíamos al Chelsea de mal en peor logró lo que se veía imposible
Venció 2-1 al Bournemouth, y con un golazo de Moisés Caicedo el conjunto londinense se clasificó a la próxima edición de la UEFA Europa League🟠
@Fut_planet⚜️#PremierLeague🏴#Chelsea🏴#UEL🟠
England Premier League🏴
2026-05-13 19:00 UTC
Manchester City vs. Crystal Palace
Predicted outcome: Manchester City✅
Predicted score: 3:1
Actual: Manchester City 3:0
#ManchesterCity#CrystalPalace
#Football#PremierLeague
England Premier League🏴
2026-04-20 19:00 UTC
Crystal Palace vs. West Ham
Predicted outcome: Draw✅
Predicted score: 1:1
Actual: Draw 0:0
#CrystalPalace#WestHam
#Football#PremierLeague
England Premier League🏴
2026-05-11 19:00 UTC
Tottenham vs. Leeds
Predicted outcome: Leeds❌
Predicted score: 1:2
Actual: Draw 1:1
#Tottenham#Leeds
#Football#PremierLeague
England Premier League🏴
2026-05-01 19:00 UTC
Leeds vs. Burnley
Predicted outcome: Leeds✅
Predicted score: 2:1
Actual: Leeds 3:1
#Leeds#Burnley
#Football#PremierLeague