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

Резултати

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

Пребарај: #zeroby30

当前筛选 #zeroby30清除筛选
#HaSab

@Hasab_2016 · Post #176 · 23.08.2025 г., 17:22

A step closer to a rabies-free community! I'm proud to share that I've been recognized as a Bronze-Level Dog Health Champion by the Global Alliance for Rabies Control (GARC). This certification fuels my passion for protecting both people and animals in our community. The best part? The training that got me here is completely free and available for everyone on the GARC website! This knowledge empowers us all to make a difference. Did you know that vaccinating 70% of dogs can break the cycle of rabies and protect everyone? As a DVM student, I am actively involved in educational activities to promote this and end the harmful practice of dog culling. I believe education is power! If you're a school, community group, or just a concerned pet owner, I'm here to help us learn together. Let's work towards the goal of #ZeroBy30! #CommunityHealth#DogVaccination#RabiesAwareness#GARC#DogHealthChampion#VeterinaryStudent#PublicHealth#LearnTogether#FreeEducation