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

Пребарај: #dst

当前筛选 #dst清除筛选
Airdrop Strikers™

@airdropstrikers · Post #266 · 29.04.2022 г., 15:17

📣📣📣DoctorS Token Airdrop $50,000 begins now: The biggest airdrop campaign of DoctorS Token $DST, we are Doctor Strange and Avengers lover community. It’s where we not only get huge earning but also sharing with many people. Let’s join and make us bigger! The DoctorS Token airdrop: 🎁 Reward: 100,000,000 $DST when you win the airdrop whitelist. 👨‍👧‍👦 Participants: Everyone 📌Registration: April 29th - May 3rd, 2022 💵Distribution: May 3rd - May 16th, 2022 🚀🚀 Click here to join: @DoctorSTokenAirdropBot More about us: 🌏Website: https://drstrangefan.io 🐦Twitter: https://twitter.com/DoctorSToken 📣Channel: @drstrangeann #DST#DSTToken#DoctorSToken#DoctorStrangeToken

🚀🚀The intelligent investors💯💯

@the_intelligent_investors · Post #421 · 05.05.2022 г., 10:43

⚡️⚡️⚡️Don't miss your chance!!! It's time to you to buy at dip price before SUPER BIG NEWS coming $DST is an only biggest community for whom love and follow Doctor Strange and Avengers team to create a meaningful and grow up decentralized-platform project together 💵💵 We're available on #coinmarketcap and live on #pancakeswap with smart contract: 0xa128a6216a8e8def817a31a06290f8055d6add2f Tax is 8-12% for Buy/Sell Find more about us: 🌏Website: https://drstrangefan.io 🐦Twitter: https://twitter.com/DoctorSToken 📣Channel: @drstrangeann 🗣 Group: https://t.me/drstrangeio #Doctorstoken#DSTtoken#DoctorStrangetoken#DoctorS #Doctorstrange#DST#DoctorStrangeInTheMultiverseOfMadness