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

Пребарај: #thng

当前筛选 #thng清除筛选

Raffle-airdrop $THNG from Drop Hunter and a mini-review of the token 😀 Things Token plans to launch an RWA platform for buying and selling real assets. It is hosted on our 🪙#TON blockchain and is already available on DEX platforms. You can learn more about the project. The conditions for the #Airdrop are below: 🟡Launch the bot. 🟡Subscribe to the channel. 🟡Invite 5 friends (old referrals count). 🟡Buy 1 ticket and wait for the results to be announced. Two-tier token system: ➖$THNGP: A token with voting rights in the DAO, mined through mining and participation in the presale. Can be exchanged for 👁#THNG at a ratio of 1:10. The transfer of this token is limited to a single transaction (for example, if you need to change your wallet). It can only be freely sent and received through mining, voting, and exchange (conversion) smart contracts. Do not attempt to sell these tokens or transfer them to exchanges. 😀$THNG: A freely tradable token for trading, transferring and other purposes. 🟡Drop type - Raffle. 🟡Total volume - 28 million $THNG coins 🟡Total winners - 400 people. 🟡For each user – $65,000 THNG for 1 ticket (50,000 points = 1 ticket) 😀 At the moment, THNG 2.0 staking is available with an APR of ~ 160% from August 23 to September 24. 🔥Keep farming and participate in all activities of DropHunters #farm#drop#TON#web3