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

Пребарај: #secondseason

当前筛选 #secondseason清除筛选
MoonPlay

@moonplay_official · Post #93 · 15.08.2024 г., 07:15

Let’s Conquer the Moon Together!🌕 Just landed on To The Moon!? Don’t worry - you’re joining at the perfect time as we kick off Season 3! Here’s how it works: 💸 mine Space Bucks, 🚀 upgrade your ship, 👥 invite friends & recruit a stellar crew, 🌌 play Star Dust to gain even more SP, 🏆 set off to the moon and level up! Every step you take brings you closer to token airdrop💸 after all 5 seasons. Focus on missions, levelling up, inviting referrals, and growing your space bucks balance. And for those of you who are starting out now, you’ve still got a shot at the airdrop by playing, conquering, and contributing to the mission. Ready to explore? Your adventure awaits! 👉TO THE MOON APP👈 Website | Telegram Chat | X | Discord | Medium #ToTheMoon#MoonPlay#ecosystem#blockchain#gamefi#web3#wenlisting#secondseason#communitymilestone#communityfirst#taptap#clicker#game

MoonPlay

@moonplay_official · Post #91 · 14.08.2024 г., 07:46

Shine Bright with Your Season 2 Badges and Win Big! 🪙 Season 2 was definitely one to remember: fierce competition, amazing Space Bucks balances, crazy level-ups 🆙, completed missions, and tons of new players joining To The Moon! via referral links 🤝. We've got plenty of reasons to celebrate! Just like we did in July - share your Achievement Badge from Season 2 2️⃣, and you could win a prize equal to the Space Bucks balance on it! Here's how to join in: 1️⃣ Follow the @moonplay_official group. 2️⃣Join our lively chat at @moonplay_chat. 3️⃣Drop a screenshot of your Season 2 Achievement Badge + use a hashtag #Season2 in the comments below this announcement. ⭐️To find your Season 2 Badge, just tap your profile in the top right and look under the Loot Capsules. We'll pick 20 lucky winners in 24 hours, so keep your eyes peeled! Good luck, and may your Badge shine the brightest! 👉TO THE MOON APP👈 Website | Telegram Chat | X | Discord | Medium #ToTheMoon#MoonPlay#ecosystem#blockchain#gamefi#web3#wenlisting#secondseason#communitymilestone#communityfirst#taptap#clicker#game