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

Пребарај: #crc

当前筛选 #crc清除筛选
Addis Standard

@addisstandardeng · Post #21338 · 07.02.2026 г., 06:16

News: #UN child Rights Committee raises alarm over grave violations against children in #Ethiopia The United Nations Committee on the Rights of the Child (#CRC) has expressed alarm over what it described as a significant increase in grave violations against children in Ethiopia, including killing and maiming, sexual violence, abduction, and denial of humanitarian access, following its latest review session covering several State Parties. Regarding children affected by armed conflicts, the Committee urged Ethiopia to comply with applicable international law, end and prevent grave violations, and allow timely and unimpeded humanitarian access. It also called on the government to urgently facilitate access to encampments to enable identification of children and their transfer to civilian child protection actors, ensure accountability for perpetrators, and provide conflict-affected children with medical care, including reproductive health services, ...... Read more: https://addisstandard.com/?p=55054

Libertà è ragione

@libertaeragione · Post #3945 · 09.09.2023 г., 10:30

#G20#India Narendra #Modi (#BJP|Destra): "Ho inviato al Presidente di turno dell'Unione africana Azali #Assoumani (🇰🇲#CRC|Centro-sinistra🇰🇲) un documento in cui si invita formalmente l'Unione come membro permanente del G20. Il documento esprime la ferma convinzione che la sua inclusione contribuirà significativamente a far fronte alla sfide globali dei nostri tempi." @OsservatorioEsteri