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

Пребарај: #tycoonseason1

当前筛选 #tycoonseason1清除筛选
SingSing Announcement

@singsingchannel · Post #1043 · 22.11.2024 г., 07:00

🚀 SingSing Launchpool: Tycoon Season 1 is Live! 🎉 🌟 Stake $SING, Earn $KARA – The In-Game Currency of Tycoon! 🌟 💰 Launchpool Overview: - Total Rewards: 1,000,000 $KARA - Period: Nov 22, 7:00 AM (UTC) – Dec 6, 6:59 AM (UTC) 💎 Staking Details: - Minimum Stake: 50 $SING - Maximum Stake: 2,000 $SING - Rewards are settled every hour based on your staked $SING share. 🎮 What’s $KARA? $KARA is the in-game currency for SingSing Tycoon, used to unlock premium upgrades, enhance gameplay, and claim exclusive rewards. 👉 How to Join: 1️⃣ Prepare your $SING tokens (at least 50 $SING to participate). 2️⃣ Stake your $SING in the Launchpool. 3️⃣ Watch your $KARA rewards roll in automatically! Note: If you have not got $SING, easily buy at: - BingX: https://bingx.com/en/spot/SINGUSDT/ - CoinEx: https://www.coinex.com/en/exchange/sing-usdt 🔥 Don’t miss this chance to boost your Tycoon gameplay – stake early for maximum rewards! #SingSing#Launchpool#TycoonSeason1#GameFi

SingSing Announcement

@singsingchannel · Post #1025 · 19.11.2024 г., 02:06

🚨 Sneak Peek! 🚨 🔥1,000,000 $KARA is within your reach! 💥 SingSing Launchpool: Tycoon Season 1 goes live this week! 🎮 💰 Stake your $SING and earn $KARA – exclusive rewards await! Tips: Make sure you have $SING to join, If you have not got $SING, easily buy at: - BingX: https://bingx.com/en/spot/SINGUSDT/ - CoinEx: https://www.coinex.com/en/exchange/sing-usdt ⏰ Mark your calendars – the countdown begins! #SingSing#Launchpool#TycoonSeason1#GameFi