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

Резултати

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

Пребарај: #lowslippage

当前筛选 #lowslippage清除筛选

Testing Bitunix: What Traders from the CIS Should Know I’ve started trying out the new Bitunix exchange, which we’ve recently partnered with. It’s great to see a Tier-1 CEX with all the tools you need, low fees, and no KYC 👍 Under the hood: ✔️Up to 8 charts in one window. Track multiple pairs at once. ✔️High liquidity. Orders execute without slippage, plus there are built-in guaranteed Stop-Loss/Take-Profit. ✔️No KYC required. A real plus. ✔️Strong CIS community support. You won’t feel ignored like on other platforms. ✔️Active marketing and tournaments. Big giveaways and contests run constantly — often bigger than the competition’s. ✔️Great partner program. The team is open to discussions — worth checking out if you’re looking for a collaboration. ✔️Impressive trading volume and insurance fund. ✔️Multiple licenses, including a U.S. license. Rare among modern CEXs. If you’re trading actively and want a fresh interface ➡️give Bitunix a try: claim 50% off trading fees. Plus, from July 26 to August 5, you can claim a futures bonus of 25, 125, or 250 USDT — depending on your deposit size (see image). #Bitunix#CryptoTrading#CEX#NoKYC#LowSlippage