TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #425 · 20 апр.

Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках. Выглядело это примерно так: from fastapi.concurrency import run_in_threadpool async def execute(data: DataRequest) -> DataResponse: try: result = await run_in_threadpool(sync_function, data) return DataResponse(data=result) except Exception as e: return DataResponse( error=str(e), success=False, ) В общем работает нормально. Для всех вызовов под капотом используется общий тредпул, всё работает предсказуемо. Но потребовалось изменить количество запускаемых в пуле потоков (по умолчанию создается 40 воркеров). Так как дело происходит с FastAPI, делается это через lifespan используя настройки anyio: import anyio @asynccontextmanager async def lifespan(app: FastAPI): limiter = anyio.to_thread.current_default_thread_limiter() limiter.total_tokens = 100 yield # если вдруг нужно вернуть обратно limiter.total_tokens = 40 Зачем менять количество воркеров? - уменьшить, если оперативки мало (один тред занимает ~8мб) - увеличить чтобы выдержать нагрузку Если есть предложения получше при тех же вводных - предлагайте😉 #async

Hashtags

Резултати

Пронајдени 6 слични објави

Пребарај: #letter

当前筛选 #letter清除筛选
Pensive|

@PensivePost · Post #4889 · 07.02.2021 г., 23:34

Dear Love, I was passing thru a tunnel, deep, long, dense and drk tunnel full of the pain and agony, freaking and frustrating. It seems there was no end to this tunnel. In despair, i approached you, took your name, imagined your smile! And to my surprise, now the tunnel has ended. A bright beam of the light showing me a path ahead. Love, smiles, happiness all what I wished ahead. It feels like you filled my path with the sun light. Yes jaan, indeed you are the sunshine for me. And Love you love, for being there as bright light for me. Love you love, for bringing lots of happiness for me. Love you love, for gifting me the infinite togetherness. Love you 💕💕💕 #letter #review

Pensive|

@PensivePost · Post #5242 · 30.05.2021 г., 05:06

To the first friend, I made You are the reason to feel and realise what friendship is and how it feels. You brought happiness to my life. You were possessive on me. You were sad when i wasn't talk with you. You motivated me. You stood by my side. You were the one who scold when I do something wrong. I never thought that you left me and found a new best friend(s) But they love you more than me. I wish you to be happy and loved always not to be with me. We still communicate now and then. But not with the same Friendship just like a stranger. You fought with others to sit near with me but now you get over me and sit in other place even when there is no competition. I'm accepted the reality. I appreciate your choice of leaving me and get more loyal, true, lovely friends. I still hope you didn't forget my friendship with you #letter#review#friendshipbreakup