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

Пребарај: #gotonapp

当前筛选 #gotonapp清除筛选
Go! Announcements

@gorwachain_announcements · Post #518 · 31.08.2024 г., 12:40

🚀 Time to Check In, Go! SmartChain AI Community! Check in now if you're yet to👇 🔗https://t.me/thegoprojectbot?start=twitter Here's an another opportunity to increase your daily dose of engagement and rewards! 🎮💰 And once you're in 1. Click "Open App" to get started 2. Tap the Go! token to collect rewards 3. Complete your daily tasks and quests to earn GoXP Most importantly, Stay active and climb your way to the top. Your participation paves the way for you 💪 #CheckIn#EarnRewards#GoSmartChain#GoTonapp ----------------- Join: 🐣X✉️Chat✉️News🤖Discord Play: 🕹️TON App💻Web App Info: 🖥Newsletter🌐Website🌐Blog

Go! Announcements

@gorwachain_announcements · Post #506 · 25.08.2024 г., 21:30

There's a lot to be made by tapping and claiming coins from the Go! Ton App! Get started Here: https://t.me/thegoprojectBot This bot is your free pass to Sweet rewards, get started Now. Once you get started, you've got to maintain your spot as a weekly and monthly active user. Here's why: 🔹 There are more rewards as you get more active 🔹 You get features nobody else gets 🔹 You get into higher ranks which means exclusive airdrops will be sent to you. 🔹 You get access to collectibles reserved just for you 🔹 You get to Contribute more to the community, and influence the direction of the project Ready to start Tapping? Let's Go: https://t.me/thegoprojectBot #gotonapp#tap2earn#bot#rewards#boost#wealth Join: 🐣X✉️Chat✉️News🤖Discord Play: 🕹️TON App💻Web App Info: 🖥Newsletter🌐Website🌐Blog