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

Резултати

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

Пребарај: #theparallel

当前筛选 #theparallel清除筛选

🎙Long waited testnet for Parallel is ON🔥🔥🔥 🎮TESTNET FOUNDATION GAME: PARAGON CRAFTING🎮 ➧REGISTER NOW! ⚖️Requirement: Have at least 1000 PRL in Wallet BUY NOW: https://poocoin.app/tokens/0xd07e82440a395f3f3551b42da9210cd1ef4f8b24 👉Registration Form: https://prl.onl/testnetform ⏰Registration Open: Jan 6, 2022 - Jan 10, 2022 ⏰Valid Wallet Scan: 13:00 UTC on Jan 10, 2022 #TheParallel#Metaverse#PRL

🔥🔥🔥ARE YOU READY? JUST 20 minutes LEFT There is nothing more excited than waiting for the Super Listing Event from The Parallel at the moment. Do not miss us! Set your alarm at 13:00 UTC right now, Parallese. Events on the Super Listing Event you should pay attention!! 👉 SQuizz Game on Livestream 🎁 20,000 PRL for the 200 people have the highest score Step 1: Log in to your MetaMask wallet address at theparallel.io Step 2: Follow the Super Listing event and wait for the questions to appear randomly throughout event time (15 questions in total) Step 3: Answer the questions at theparallel.io 👉 Share NOW - Earn NOW - 🎁 20,000 PRL for 1,000 fastest Parallese sharing and $1000 for 1 luckiest one Step 1: Share the Livestream on Facebook or Twitter with the hashtag #TheParallel#Super_Listing_Event#Metaverse#PRL Step 2: Tag 5 of your friends in the comment section Step 3: Enter the link of your sharing post and your wallet address at: https://t.me/prlsharenowbot 📌 Listing time: Revealed in the Livestream. You must watch the full live stream to find out 🔐 PRL smart contract address: 0xd07e82440A395f3F3551b42dA9210CD1Ef4f8B24 1️⃣ Install BEP-20 Wallet (Metamask) 2️⃣ Adding PRL smart contract before Listing will help shorten transaction time and increase fair competition with bots. 3️⃣ Prepare BUSD, BNB in your wallet and approve BUSD in PancakeSwap 📎 Find out details at: https://prl.onl/3FqvCrh

🎙The Parallel - An Infinite Metaverse announcement🔥🔥 The Parallel - An Infinite Metaverse@theparallel_io Feb 23👑 Check Out Rune Hunter: Ascension! First game launched by The Parallel Metaverse 👉Read the game guide! We want your first impressions and thoughts! 👉Checkout Ascension NOW:https://prl.onl/3LU3xfv ⏰ ETA: Mid March Testnet #Gamefi#playtoearn$PRL #PRL#theparallel#Ascension