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

Пребарај: #selfsufficiency

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

@CryptoM · Post #65247 · 12.04.2026 г., 09:19

🚀 STOCKS | Galaxy Securities Highlights Opportunities Amid Rising Oil Prices On April 12, Galaxy Securities released a report noting that March's Producer Price Index (PPI) turned positive year-on-year, driven by high oil prices and ongoing policy efforts. According to Jin10, the report emphasizes the potential for profit recovery in China's A-share market, particularly in upstream sectors. The report identifies several investment opportunities. Firstly, it suggests focusing on energy and alternative demand sectors, including coal, coal chemicals, new energy, shipping ports, and oil and gas. Additionally, there is potential for recovery in the non-ferrous metals sector, including precious and minor metals. Secondly, the report highlights defensive assets such as finance (banks), utilities, and transportation. Thirdly, it points to technology innovation and self-sufficiency sectors, including power equipment, energy storage, semiconductors, computing power, and communication equipment. In the consumer sector, it suggests focusing on agriculture, forestry, animal husbandry, fisheries, food and beverages, and household appliances. The report also notes that if there are signs of easing in ongoing conflicts, there could be significant recovery opportunities in previously oversold sectors. #GalaxySecurities#OilPrices#ProducerPriceIndex#ProfitRecovery#AShareMarket#UpstreamSectors#EnergySector#AlternativeDemand#Coal#NewEnergy#ShippingPorts#OilAndGas#NonFerrousMetals#PreciousMetals#DefensiveAssets#Finance#Utilities#Transportation#TechnologyInnovation#SelfSufficiency#PowerEquipment#EnergyStorage#Semiconductors#ComputingPower#CommunicationEquipment#ConsumerSector#Agriculture#FoodAndBeverages#HouseholdAppliances#RecoveryOpportunities