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

Резултати

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

Пребарај: #mimicry

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

@interesting_planet_facts · Post #614 · 23.08.2025 г., 13:22

🌎 The lyrebird’s call isn’t its only quirky skill—it can mimic the sound of chainsaws, camera shutters, and even car alarms, thanks to the most complex vocal organs in the bird world. These copycat birds help signal their territory and attract mates, showing off nature’s ultimate vocal impressionist. ✨ #birds⚡#mimicry⚡#nature 👉subscribe Interesting Planet ​

Interesting Planet 🌍

@interesting_planet_facts · Post #446 · 28.07.2025 г., 13:22

🌎 The blue poison fang blenny avoids predators by mimicking deadly fish and carrying real toxins in its bite—one of the few venomous fish that inject opioid-like chemicals, numbing attackers instantly. ✨ #venom⚡#mimicry⚡#ocean 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #1123 · 12.12.2025 г., 18:11

🌎 The male Australian superb lyrebird can mimic over 20 different bird species and even human sounds. Its tail feathers form a fan shape used in courtship displays. Lyrebirds have the most complex vocal repertoire of any songbird, with some males learning new sounds throughout their lives. ✨ #lyrebird⚡#adaptation⚡#mimicry 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #459 · 29.07.2025 г., 17:22

🌎 The mimic poison frog of Central America’s rainforests sports dazzling colors that copy other toxic frogs, deterring predators through clever visual deception rather than its own strong toxins. ✨ #rainforest⚡#mimicry⚡#frogs 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #573 · 16.08.2025 г., 20:22

🌎 The bolas spider swings a sticky silk “lure” scented like female moths to attract unsuspecting mates—then snags them midair in a single swoop! ✨ #spider⚡#mimicry⚡#hunting 👉subscribe Interesting Planet