Три способа выполнить множество задач с 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
#everyone The submission window for our $SAHARA Priority Allocation is now closed.
Thank you to everyone who submitted thoughtful and original content supporting Sahara AI 💙🔆
Every submission will undergo a manual review for quality. Selected contributors will receive an email by June 10 at 00:00 AM UTC with:
• Their unique invitation code
• Priority Allocation amount
• Steps to complete KYC and subscribe
If you participated, please keep an eye on your inbox (and spam folder) for updates from Buidlpad.
We’re proud to recognize and reward the community members creating value around Sahara AI. Stay tuned for the upcoming KYC Stage!
@gBuidl💙
*Who Am I*
Ah! This drizzling rain
Those lovely skies
I love it all
I don't know why
These twinkling stars
That lovely moon
I wanna see them
Even in the noon
I wanna run
I wanna fly
Do everything possible
Before I die
That's what a part of me
Always says
The part I wish could
Forever stay
But in this world
That's not the case
Like every coin
I have another face
The one which is scared
The one which is shy
Wanting to be heard
Almost ready to cry
That me doesn't have
A place to go
Neither when I burn
Nor when I glow
I spend nights wondering
Which of them is right
I often put them in a battlefield
But they refuse to fight
So now I'm really confused
I don't know why
All I wanna know is
who am I ..
#review#everyone#poem
*Perhaps my soul is dark*
I am drawn into your world
That you so darkly carved
With your emptiness
Perhaps my soul is dark
Perhaps I like black holes
Perhaps I hope to emerge
On the other side as bright
As a brilliant.radiant star
That lights up a million worlds
Im sorry Jasmine
I am drawn to your dark nudity
The poverty of your humanity
Perhaps my soul is dark
Perhaps I like the thorns better
Than the roses and the fragrance
Of blood better than jasmine
Perhaps I want to break through
The darkest night pouring into
A zig zillion shards of light
silently making a new dawn
#review, #RC, #Everyone, #poetry
The beau, ignorance.
I knew.
That made me a shitty person
If there was anything that made it unbearable and more hard to overcome than anything, it’s the fact that I knew it was going to happen.
It’s a pity we don’t get to un-know stuff.
Like just trash it.
It felt(no, was )wrong.
Like hoarding the girls lavatory or cyber bullying overweight people because it felt right
Or self-hurting so you can feel anything other than this unimaginable sorrow that was slowly drowning you.
If there was anything that was worse than knowledge, it’ll be passivity, more like apathy.
The fact that you didn’t act.
That I didn’t act
This didn’t feel wrong.
It didn’t feel like anything I have ever felt.
Words can’t quantify how it feels.
Probably, nothing will.
I hope nothing does.
Excerpt from my book, For the Lies that Matter
@whosayegat
#review
#everyone
#excerpts
R-r人r人r都d说s我w爱a你n- 人人都说我爱你 Everyone Says I Love You (1996)
直达链接:https://pan.quark.cn/s/6a7fc5716f09
#人人都说我爱你#Everyone Says I Love You
#大家都说我爱你#为你唱情歌
链接:https://link3.cc/sf_com
#电影#喜剧#美国#90年代