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

Резултати

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

Пребарај: #wednesdayfrog

当前筛选 #wednesdayfrog清除筛选
Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40818 · 18.03.2026 г., 11:01

Glass frogs are small tree frogs that live in tropical forests in Central and South America. Some species have transparent bellies, so their heart and organs can be seen through the skin. This helps them hide from predators. Most glass frogs are light green and live on leaves near streams. They use sticky toe pads to climb and stay on surfaces. There are about 160 species of glass frogs. 🐸🌿🌎. [Read more 1] [Read more 2] @googlefactss #Animals#Nature#DidYouKnow#Wildlife#Science#WednesdayFrog

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40855 · 24.03.2026 г., 23:01

Boreal chorus frogs can make their loud, high-pitched “reeeek” calls underwater, which is rare among frogs. They are small frogs found in Canada and the northern United States, usually growing to about 3 centimeters long. Their bodies are brown, tan, or green, and they often have three dark stripes running down the back and a dark line through each eye. They live near ponds, marshes, and wetlands. Males call in groups to attract mates and warn other males. Calls are most common during the spring breeding season. 🐸🌿🌊 [Read more 1] [Read more 2] @googlefactss #Animals#Nature#Frogs#Wildlife#DidYouKnow#Communication#wednesdayfrog