Функция asyncio.wait() это еще один способ вызвать множество асинхронных задач.
Она работает в нескольких режимах.
1. Самый простой - ждем завершения всех задач
async def main():
tasks = [asyncio.create_task(do_it(i)) for i in range(10)]
done, pending = await asyncio.wait(
tasks,
return_when=asyncio.ALL_COMPLETED
)
for task in done:
try:
print(task.result())
except Exception as e:
print(e)
Очень похоже на gather, но работает не так.
▫️возвращает не результаты, а два сета с объектами Task у которых можно забрать результат через task.result() если они в списке done
▫️не гарантирует порядок результатов так как оба объекта это set
▫️не выбрасывает исключение когда оно появляется, а сохраняет его в Task. Исключение появится когда попробуете забрать резултьтат.
2. Ждем завершения первой задачи, даже если там ошибка.
async def main():
tasks = [asyncio.create_task(do_it(i)) for i in range(3)]
done, pending = await asyncio.wait(
tasks,
return_when=asyncio.FIRST_COMPLETED
)
# в done может быть несколько задач!
for task in done:
try:
print(task.result())
except Exception as e:
print(f"Fail: {e}")
# Оставшиеся задачи в pending, как правило, нужно отменить, иначе они будут продолжать работать
for task in pending:
task.cancel()
В сете done будут таски которые успели завершится, причем как успешно так и нет.
3. До первой ошибки.
Тоже самое, но с аргументом FIRST_EXCEPTION
done, pending = await asyncio.wait(
tasks,
return_when=asyncio.FIRST_EXCEPTION
)
Функция завершается как только первая задача упадет с ошибкой.
Учтите, что в любом случае done вы можете обранужить несколько задач, как с ошибками так и успешные.
↗️ Полный листинг примеров здесь
#async
🛎#FREESIGNAL
Make a LONG/BUY ORDER on #BTC/USDT from 80100 on Futures
Leverage - 5x - 10x - 25x - 50x
👁🗨Contact @cripexperts to enter the premium group & trade with perfect targets & stop loss levels
🚨#FREESIGNAL🚨
#BTC/USDT – LONG/BUY
📉 Entry: $92,400
📊 Leverage: 5x /10x /25x / 50x
📍Platform: Futures
🔥 This is a free trade idea — Premium members get full TP/SL levels and real-time updates!
💬 DM @cripexperts to join the Premium Group
✅ Trade smart. Trade with confidence.
🚨#FREESIGNAL🚨
#BTC/USDT – SHORT/SELL
📉 Entry: $91,350
📊 Leverage: 5x /10x /25x / 50x
📍Platform: Futures
🔥 This is a free trade idea — Premium members get full TP/SL levels and real-time updates!
💬 DM @cripexperts to join the Premium Group
✅ Trade smart. Trade with confidence.
🛎#FREESIGNAL
Make a LONG/BUY ORDER on #BTC/USDT from 80100 on Futures
Leverage - 5x - 10x - 25x - 50x
👁🗨Contact @primemod to enter the premium group & trade with perfect targets & stop loss levels
🛎#FREESIGNAL
Make a LONG/BUY ORDER on #BTC/USDT from 68640 on Futures
Leverage - 5x - 10x - 25x - 50x
👁🗨Contact @primemod to enter the premium group & trade with perfect targets & stop loss levels
🚨#FREESIGNAL🚨
#BTC/USDT – LONG/BUY
📉 Entry: $92,400
📊 Leverage: 5x /10x /25x / 50x
📍Platform: Futures
🔥 This is a free trade idea — Premium members get full TP/SL levels and real-time updates!
💬 DM @primemod to join the Premium Group
✅ Trade smart. Trade with confidence.
🚨#FREESIGNAL🚨
#BTC/USDT – SHORT/SELL
📉 Entry: $91,350
📊 Leverage: 5x /10x /25x / 50x
📍Platform: Futures
🔥 This is a free trade idea — Premium members get full TP/SL levels and real-time updates!
💬 DM @primemod to join the Premium Group
✅ Trade smart. Trade with confidence.
🔅BITCOIN Will Go Down From Resistance! Sell!📉
- - - - - - - -
Please, check our technical outlook for 📊BITCOIN.
The market is approaching a key horizontal level 78,161.73.
Considering the today's price action, probabilities will be high to see a movement to 77,165.90.
- - - - - - - -
#freesignal#bitcoin
- - - - - - - -
🌐Free Copy Trading: Link
📲Join VIP via Bot:Link
❓Official Contact:@signalprovidercontact
🔅BITCOIN Will Go Lower From Resistance! Sell!📉
- - - - - - - -
Please, check our technical outlook for 📊BITCOIN.
The market is trading around a solid horizontal structure 73,205.33.
The above observations make me that the market will inevitably achieve 68,619.32 level.
- - - - - - - -
#freesignal#bitcoin
- - - - - - - -
🌐Free Copy Trading: Link
📲Join VIP via Bot:Link
❓Official Contact:@signalprovidercontact
🔅BITCOIN Will Grow! Buy!📈
- - - - - - -
Here is our detailed technical review for 📊BITCOIN.
The market is on a crucial zone of demand 69,527.38.
The oversold market condition in a combination with key structure gives us a relatively strong bullish signal with goal 70,433.22 level.
- - - - - - - -
#freesignal#bitcoin
- - - - - - - -
🌐Free Copy Trading: Link
📲Join VIP via Bot:Link
❓Official Contact:@signalprovidercontact
🔅BITCOIN Will Go Up! Buy!📈
- - - - - - -
Here is our detailed technical review for 📊BITCOIN.
The price is testing a key support 69,833.99.
Current market trend & oversold RSI makes me think that buyers will push the price. I will anticipate a bullish movement at least to 71,850.50 level.
- - - - - - - -
#freesignal#bitcoin
- - - - - - - -
🌐Free Copy Trading: Link
📲Join VIP via Bot:Link
❓Official Contact:@signalprovidercontact
🔅BITCOIN Is Very Bearish! Sell!📉
- - - - - - - -
Please, check our technical outlook for 📊BITCOIN.
The market is trading around a solid horizontal structure 70,229.88.
The above observations make me that the market will inevitably achieve 69,008.56 level.
- - - - - - - -
#freesignal#bitcoin
- - - - - - - -
🌐Free Copy Trading: Link
📲Join VIP via Bot:Link
❓Official Contact:@signalprovidercontact