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 слични објави

Пребарај: #toxins

当前筛选 #toxins清除筛选
Interesting Planet 🌍

@interesting_planet_facts · Post #1241 · 20.01.2026 г., 22:11

🌎 Golden poison dart frogs from Colombia are among the world’s most dangerous animals. Their skin holds enough potent toxin to kill up to 10 adults. The toxin, called batrachotoxin, blocks nerve signals to muscles, causing paralysis and death even in small doses. ✨ #animals⚡#toxins⚡#Colombia 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #499 · 04.08.2025 г., 18:22

🌎 The rainbow mantella frog of Madagascar sports neon green and orange skin, warning predators of its toxicity. These tiny amphibians gain their deadly defenses from eating certain ants and mites in the wild. ✨ #amphibians⚡#Madagascar⚡#toxins 👉subscribe Interesting Planet

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40101 · 16.11.2025 г., 11:00

That "new car smell" is a toxic chemical cocktail! ☠️ You're breathing VOCs from plastics, foam, and adhesives—including formaldehyde. It's essentially off-gassing from your car's interior. Carmakers are now phasing it out for health reasons. [Read more] @googlefactss#NewCarSmell#Toxins#HealthWarning#CarFacts