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

Пребарај: #pipelineattack

当前筛选 #pipelineattack清除筛选
Crypto M - Crypto News

@CryptoM · Post #64893 · 10.04.2026 г., 07:25

🚀 Oil Prices Rise Ahead of U.S.-Iran Talks, Remain Below $100 per Barrel Oil prices have increased but remain below $100 per barrel as the U.S. and Iran prepare for talks this weekend. According to Odaily, Emmanuel Belostrino, head of global crude oil and geopolitical market data at Kpler, stated that the outcome of the negotiations, particularly the possibility of establishing a viable shipping agreement, is crucial to alleviating the current backlog. During early European trading, both U.S. and Brent crude saw short-term gains, with prices at $99.7 and $97.6 per barrel, respectively. The Strait of Hormuz remains largely frozen, causing supply disruptions and maintaining market tension. Additionally, Iran's attack on Saudi Arabia's main export route, the East-West pipeline, has reduced its daily capacity by approximately 700,000 barrels. #OilPrices#USIranTalks#CrudeOil#BrentCrude#MarketTension#OilSupply#HormuzStrait#SaudiArabia#PipelineAttack#EnergyMarket