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

Резултати

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

Пребарај: #rm

当前筛选 #rm清除筛选
Bts.bighitofficial

@OUR_7_PRINCES · Post #114718 · 19.07.2025 г., 16:43

Tae Hoon Lee (Nike’s Korea Marketing Director) shared a picture of #RM with J-Hope and Suga at the wedding. #INFO •@OUR_7_PRINCES•

Hashtags

Bts.bighitofficial

@OUR_7_PRINCES · Post #113772 · 18.06.2025 г., 23:26

#RM via Amalia Wirjono (Museum MACAN's Head of Development) instagram. https://www.instagram.com/p/DLDS91PTkYX/?igsh=aGU2ZXc2bGk2cGw2 #INFO •@OUR_7_PRINCES•

Hashtags

Bts.bighitofficial

@OUR_7_PRINCES · Post #115031 · 01.08.2025 г., 08:42

RM INSTAGRAM STORY UPDATE 💜 Translation Weren’t you curious? You must have been very curious. But writing is something you keep doing because you think you can’t help it, even if you won’t become a good writer. They probably kept writing, and by doing so, they became writers. Now they are probably getting asked the same question I get: ‘Did you always think you’d become a writer?’ If you live like a useless boat drifting with the tide, you eventually arrive somewhere. That is the future. And it comes even if you do nothing. When you finally reach that future, there is something everyone does—rewrite the preface of the past to match the ending [this quote is from a book. It’s attributed to Kim Young-ha (김영하) and appears in his novel A Single Life (단 한 번의 삶) .] #RM | #INSTAGRAM •@OUR_7_PRINCES•

Bts.bighitofficial

@OUR_7_PRINCES · Post #114715 · 19.07.2025 г., 16:42

#RM via rkive repost: 1. Eyes Magazine editor Jin Pyo: “Kim euri @ rkive You’re really a good host/MC.” 2. Post Archive Fasion Creative Director Lim Dongjoon: “You're the best MC/host I've ever seen...” #RM | #INSTAGRAM •@OUR_7_PRINCES•

ПретходнаСтраница 1 од 4Следна