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

Резултати

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

Пребарај: #fish

当前筛选 #fish清除筛选

Hey Skill Labs community, have you already played our fishing game on Discord?🐠🧩 👉 Join our Discord NOW: https://discord.com/invite/skilllabs 👉 Go to the channel called: #fish (in the offtop section) and see the rules in a pinned message 👉 We are currently hosting tournaments!

Hashtags

TonOrbital

@tonorbital · Post #243 · 25.06.2024 г., 18:01

🎉 Exciting News from #FISH! 🎉 Minting for @RetardinoTON gamepass NFTs is now live! 💫 In the upcoming patch, players can also purchase amazing cosmetic items associated with RetarDino partners. 📈 As a bonus, 50% of the profit will go towards the buyback and burn of #FISH tokens. 🎮 Don't miss out—owning an NFT is your exclusive gateway to play and earn $WFOSS. Let the adventure begin!

Hashtags

Beneficial Fishing - You Got 10 BUSD 🤑 Do you remember that Skill Labs launched a Fishing game on Discord? 🔝 We summarized the first results and decided to give 10 BUSD for TOP-5 on the list 🪝 From now, Skill Labs announcing a small tournament for everyone, you play - you earn 👉 Join our Discord and play: https://discord.gg/skilllabs 👉 Go to the channel named: #fish (the offtop section) The results will be published on May 13th 🚀 🐡🐠🐟

Hashtags

Play in Discord and get rewards 🕹 Hey Skill Guilders, let's play the fishing game using our Discord bot 🦈 👉 Join our Discord: https://discord.gg/skillguilds 👉 Go to the channel called: #fish (the offtop section) 👉 There you will see a pinned message with rules and a tutorial on how to play 🧩 Play the game and complete daily quests using the command: %quests Very soon we will launch a tournament among our community, be ready and train yourself 💪 Join now: https://discord.gg/skillguilds

Hashtags

ПретходнаСтраница 1 од 5Следна