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

Резултати

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

Пребарај: #marykay

当前筛选 #marykay清除筛选
Quiet World 🍁

@QuietWorld · Post #7330 · 04.06.2020 г., 06:58

Hi dear subscribers! 🤗🥳 How have you been? I hope everyone is healthy and may God bless you in many ways 🥰 Sorry for not posting more often in this channel, I've been catching up with works and recharging myself. & recently I've started my journey as Mary Kay Independent Beauty Consultant (IBC) 🥳 If you love Mary Kay like I do, or you wonder how good Mary Kay is, come and visit my Instagram: https://instagram.com/marrdiimarykay?igshid=g7wvrem79mj3 You can DM me there if you want to buy Mary Kay products. & if you want to be one of Mary Kay IBC, you are very welcome too! Just DM me, don't worry if you don't have any clue about it yet because in Mary Kay, we help and build each other 🥰 There's a lot more things to share but well if you want to know more, why not visit and follow my Instagram? Come come 🥰 https://instagram.com/marrdiimarykay?igshid=g7wvrem79mj3 #marykay#marykaymalaysia#marykaysabah ✅ Free postage in Malaysia @quietworld🍃