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

Резултати

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

Пребарај: #blockchainrevolution

当前筛选 #blockchainrevolution清除筛选
DigitalGenie Trading News

@digitalgentop · Post #36 · 21.05.2024 г., 19:44

🔥 Mastercard, Citigroup, and JPMorgan Chase join forces to pilot shared ledger technology for Tokenized Assets settlement processes, with the goal of enhancing speed and security in cross-border transactions. This collaboration could transform the financial sector by enabling diverse asset types to settle on a unified platform.⭐️🌐 #Cryptoassets #Cryptosuccess #Blockchainrevolution

Crypto Fight || News 🚀

@cryptofightnews · Post #2287 · 18.12.2024 г., 19:45

🚨 THE ICO IS NOW LIVE FOR EVERYONE! 🚨 🔥 The Public Phase Has Officially Begun! 🔥 This is your chance to secure $STAY tokens and join the Web3 travel revolution! Don’t miss out on this groundbreaking opportunity. Why $STAY? 🌍 One Price for All – Fair access for every participant. 📈 Top 3 Exchange Listing Soon – Be ready for the next big thing. 💰 Low FDV at 35M USDT – Strong fundamentals for sustainable growth. 🌟 Jeff Hoffman as Lead Advisor – The visionary behind Booking.com. ⚽ Global Football Ambassador – Uniting sports and travel innovation. 🏨 2.5 Million Onboarded Stays – Endless travel possibilities. 🤝 Official Partner: Huawei – Driving innovation together. Why Act Now? 💎 Double Your Tokens Potential – The time to maximize your gains is now! ⏳ Tokens Are Selling Fast – Don’t miss your chance to be part of the future of travel. 🌐 Grab Your $STAY Now: 👉community.staynex.vip 🎁 Participate in Extra $STAY Rewards: 👉reward.staynex.vip 🔽 Learn More: bit.ly/StaynexICO Risk Disclaimer: Investing in cryptocurrencies involves significant risks. Please understand that your funds are your responsibility. Always Do Your Own Research (DYOR) before making investment decisions. #Staynex#ICO#CryptoLaunch#Web3Travel#BlockchainRevolution#Crypto#STAY#Tokenomics

🚀🚀The intelligent investors💯💯

@the_intelligent_investors · Post #1632 · 01.02.2025 г., 08:34

🚀 Blockchain Energy is LIVE! 🔥 The world’s first physical blockchain product is here—introducing Blockchain Energy! 💥 Our website and ICO are officially LIVE, and early buyers can now purchase BET tokens at. www.blockchainenergy.co.uk. 💰 Buy early before prices increase! Price alerts and community updates will be shared exclusively on our Telegram group – join now: https://t.me/+vLcj22SyWvY2ZDg0 🔗 Powering the future of blockchain with real-world energy! #BlockchainEnergy#BETToken#CryptoLaunch#ICO#BlockchainRevolution#CryptoCommunity#Web3#CryptoInvesting#TokenSale#CryptoPresale