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

Пребарај: #fintopio

当前筛选 #fintopio清除筛选

We start the year with another event — SE Telegram Builders Day in Hong Kong from @epicweb3!🪭 The day before Consensus HK starts, speakers from #Blum, #TerminalStation, #AnimocaBrands, #StormTrade, #Fintopio, #TONFoundation and other projects will gather on one stage. Participants will discuss the latest trends, attracting users and investments, secrets of viral projects, the future of the ecosystem and much more that awaits us in 2025. The event is FREE, but places are limited, so hurry if you want to join. 🗓️February 17, Hong Kong 🎫Get a free ticket👈

🤩Fintopio is a new non-custodial wallet in the TON ecosystem #Fintopio is a cryptocurrency wallet in🪙 Telegram, which can be used via mini app and website. With its help, you can conveniently use #DeFi and #CeFi functions, pay bills, divide expenses, buy goods and transfer money without leaving the application. To get started quickly, you can import an existing wallet: 🟡Open "DeFi" tab in the Fintopio app 🟡 Click "View all" 🟡 Next – “Import wallet” 🟡 Enter your 12-word secret phrase to import your wallet 👛Currently the wallet supports: #BTC, #USDT [#ERC20/#TRC20], #ETH, #TRX and #TON. 📲 The project has a game to attract an audience where $HP (Hold Points) are farmed. You need to collect coins every 8 hours and in the future you can exchange them for the main utility token of Fintopio named $HOLD. The token is only available to early participants of the project, the more you #HOLD, the more rewards you will receive from Fintopio. So it's better to start right now!🚀 Game | Channel | Website