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

Пребарај: #icts

当前筛选 #icts清除筛选
Russian Mission to ASEAN

@aseanrussia · Post #1033 · 24.05.2024 г., 13:32

🗓 On May 23-24, Moscow hosted the 3rd ASEAN Regional Forum (#ARF) Workshop on Countering the Use of ICTs for Criminal Purposes, co-chaired by Russia 🇷🇺, Thailand 🇹🇭 and China 🇨🇳. 🔹️The agenda of the workshop covered such issues as criminalization and crime prevention, international cooperation on countering the use of #ICTs for criminal, terrorist and extremist purposes, as well as international legal aspects of countering the use of ICTs for criminal purposes and the practice of national and cross-border investigations. 🔹️The participants shared their approaches to the topical issues related to countering the use of ICTs for criminal purposes. The discussion highlighted the need to enhance practical cooperation in this field and to early elaborate under the UN auspices the comprehensive international convention on countering the use of ICTs for criminal purposes.

Hashtags

Russian Mission to ASEAN

@aseanrussia · Post #492 · 21.06.2023 г., 11:15

🗓 On June 21, Russia 🇷🇺 and Cambodia 🇰🇭 co-chaired 2nd ASEAN Regional Forum (#ARF) Workshop on Terminology in the Field of Security of and in the Use of ICTs in the Context of Confidence Building. More than 17 ARF Members took part in the meeting. 🔹️Representatives of specialized government agencies and academia discussed topical issues related to using specific terminology, shared their national experience and approaches in developing terminology in the field of security of and in the use of #ICTs. The participants also touched upon terminological aspects in the context of the work on universal #UN convention on countering the use of ICTs for criminal purposes. #ARF#ICT