Три способа выполнить множество задач с 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
📩#DOTUSDT 30m | Mid-Term
📉Long Entry Zone: 7.069-6.792
🎯Accuracy of this strategy - 88.26%
- ⏳ - Signal details:
Target 1: 7.126
Target 2: 7.182
Target 3: 7.239
Target 4: 7.408
_____
🧲Trend-Line: 6.792
❌Stop-Loss: 6.737
💡After reaching the first target you can put the rest of the position to breakeven
Now is the moment to determine whether the bulls are ready to charge or if the bears will take over. Here's what you need to know:
#DOTUSDT is showing promising signs of a bullish continuation from the demand zone around $4.000. The falling wedge formation we've been tracking has broken to the upside, and momentum is building within this crucial area. Should this momentum persist, we could be on the brink of a significant bullish surge.
#DOTUSDT
💢 shows that it is ready for an upward movement after the sharp drop it had and the correction movement it made recently. But its corrective movement is not over yet and we expect the 3.822-3.812 range to fall.
And after that, it can move upwards, which should break its downward trend, and the target that can be used for this upward movement is 4.282 - 4.717 - 5.097.
#DOTUSDT💢 Polkadat is in a descending channel that has reached an important support area on the daily chart.
I think there is a good buying opportunity, you can prepare yourself for a possible profit of 50% by buying at this level.
---
Polkadot находится в нисходящем канале, который достиг важной зоны поддержки на дневном графике.
Я думаю, что это хорошая возможность для покупки, вы можете подготовиться к возможной прибыли в 50%, купив на этом уровне.
---
پولکادات در یک کانال نزولی قرار دارد که به یک منطقه حمایتی مهم در نمودار روزانه رسیده است.
فکر میکنم فرصت خرید خوبی وجود دارد، میتوانید خودتان را برای احتمال سود ۵۰٪ با خرید در این سطح آماده کنید.
---
Polkadot, günlük grafikte önemli bir destek alanına ulaşmış olan düşen bir kanal içinde bulunuyor.
Bu seviyeden satın alarak %50'lik olası bir kâr için kendinizi hazırlayabilirsiniz; bence bu iyi bir alım fırsatı.
📩#DOTUSDT 30m | Mid-Term
📈Long Entry Zone: 1.233-1.191
🎯 - Strategy Accuracy: 87.54%
Last 5 signals: 80.0%
Last 10 signals: 80.0%
Last 20 signals: 87.5%
⏳ - Signal details:
Target 1: 1.243
Target 2: 1.253
Target 3: 1.263
Target 4: 1.292
_____
🧲Trend-Line: 1.191
❌Stop-Loss: 1.181
💡After reaching the first target you can put the rest of the position to breakeven
#ID20000037761