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

Пребарај: #aip

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

@addisstandardeng · Post #21251 · 30.01.2026 г., 11:59

News: #Ethiopia says official creditors decline Eurobond restructuring terms, plans to reengage Ad Hoc Committee The Ministry of Finance said Ethiopia will not proceed with the implementation of recently agreed #Eurobond restructuring terms after the country’s Official Creditor Committee (#OCC) concluded that the deal does not fully comply with the principle of Comparability of Treatment. In a statement issued on 30 January, the ministry said the assessment followed consultations with the OCC and the International Monetary Fund (#IMF) after Ethiopia reached an agreement in principle (#AIP) on 2 January 2026 with a group of bondholders on restructuring its US$1 billion 6.625% Notes due 2024. According to the ministry, Ethiopia and its advisers engaged the OCC and the IMF to determine whether the AIP was consistent with “(i) the Comparability of Treatment principle as applied by the OCC and (ii) the targets and parameters of Ethiopia’s IMF program.”...... Read more: https://addisstandard.com/?p=54853

100K20

@science_100k20 · Post #109 · 16.10.2023 г., 13:26

Предлагаем ознакомиться с графиком вебинаров от ведущих международных издательств на ближайшую неделю: 📅17 октября 2023 в 17:00 (мск) ✅AIP | Вероятностные модели и их применение Регистрация доступна по ссылке. 📅 18 октября 2023 в 17:00 (мск) ✅Questel | Базовый тренинг по Orbit Intelligence Регистрация доступна по ссылке. 📅18 октября 2023 в 19:00 (мск) ✅ACS | Сила химии: Передовые исследования в области антибиотиков и генной терапии Регистрация доступна по ссылке. #вебинар#исследования#электронныересурсы#наука#библиотека#публикации#ACS#AIP#Questel