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

Пребарај: #stayupdated

当前筛选 #stayupdated清除筛选
MXPlayer Official

@mxofficialchannel · Post #513 · 07.10.2023 г., 15:59

​​Your favourite entertainment platform is now on WhatsApp Channels 🤗 Join now to get all the latest updates about your favorite shows and movies, right in WhatsApp. 🤔 So what are you waiting for? Join MXPlayer's Official WhatsApp Channel today, and get your daily dose of entertainment 🎬🎭 #MXPlayerOnWhatsApp#JoinTheFun#StayUpdated

SingSing Announcement

@singsingchannel · Post #813 · 20.09.2024 г., 09:03

🚨 New Tycoon Game Coming Soon! 🚨 Don't miss out on all the exciting updates! 🎉 Make sure to update your bookmarks with SingSing's latest social channels for valuable info on our upcoming releases: 🔗 Telegram Channel: https://t.me/singsingchannel 🔗 Telegram Chat: https://t.me/singsingglobal 🔗 X (Twitter): https://x.com/singsingglobal 🔗 Website: https://singsing.net/ 🔗 Game Mini App: https://t.me/SingSing_TG_bot Stay tuned, something BIG is coming! 🎮✨ #SingSing#KaraokeTycoon#NFT#GameFi#StayUpdated Announcement | Chat | X (Twitter) | Website | Game

Go! Announcements

@gorwachain_announcements · Post #513 · 29.08.2024 г., 10:54

⚡️Never miss an opportunity to stay ahead of the Curve with Go! 🔗 Official Telegram https://t.me/gorwachain 🔗 Official Discord https://discord.gg/gorwachain Go! Smartchain AI is a hub of innovations and always has juicy opportunities in store for you What better way to harness these opportunities than joining the official platforms👇 Don't enjoy this privilege alone. Share the links to your friends to join in too. The more, the merrier 💥 #gosmartchainAI#Followup#Stayupdated#Discord#telegram Join: 🐣X✉️Chat✉️News🤖Discord Play: 🕹️TON App💻Web App Info: 🖥Newsletter🌐Website🌐Blog