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

Пребарај: #strategicstability

当前筛选 #strategicstability清除筛选

@RusEmbMalta Press Release On the Development of a Global Missile Defense System by the United States 🇷🇺 The Embassy of the Russian Federation underscores that the concept of a global missile defense system is fundamentally flawed and cannot ensure protection against a potential retaliatory strike by Russia’s strategic forces. Its creation is therefore not only ineffective but also strategically unsound. ️🔹 NATO bears direct responsibility for the dismantling of international legal mechanisms that once upheld strategic stability and predictability in global affairs. The persistent unwillingness of NATO member states to engage in constructive dialogue with Russia further exacerbates military–political tensions, undermining collective security. ❗ We recall that the United States unilaterally rejected cooperation under Russia’s 2010 initiative for a collective European missile defense system – an approach that could have fostered genuine partnership rather than confrontation. Equally untenable are the deceptive assurances of NATO leadership that the deployed missile defense infrastructure is not aimed against Russia’s nuclear potential. These claims directly contradict NATO’s own recent statements identifying Russian strategic forces as a primary target of the system. Such inconsistency reveals the real nature of this project. 🔹It is evident that the driving force behind the expansion of U.S. missile defense capabilities abroad is not global security, but rather the financial interests of the American military–industrial complex. 🔹 Russia reaffirms its commitment to strategic stability, predictability, and equitable security for all nations, and calls upon partners to return to serious dialogue rather than the pursuit of illusory and destabilizing military solutions. #MissileDefense #GlobalSecurity #StrategicStability #ArmsControl