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

Пребарај: #cfmoller

当前筛选 #cfmoller清除筛选

Large-scale transformation and adaptive re-use in Oslo🇳🇴 Images of the new proposal for Oslo Horizon - KLP’s high-rise hub - submitted to PBE / Oslo planning authority. The scheme seeks to transform a former post office terminal into a new gateway to Oslo central stations rail platforms, and creating a commercial multi-tenant office hub w.3500 workspaces, a hotel/ conference centre, foodcourt and cafe + over 3000 cycle parking spaces. Between tree branches in an extensive green roofscape the public can experience panoramic views of the Oslo Fjord and biodiversity in the heart of Oslo. Oslo Horizon will be one of the Norway’s largest and most ambitious transformation projects, pioneering applications of re-use and recycling on an international scale. Made by CF Moller Architects in collaboration with: kristin jarmund architects androdeo arkitekter. #architecture#cfmoller#cfmollerarchitects#archilovers#improveLifeforPeopleandPlanet#dezeen#archdaily#oslo#norway#arch_shovel

The Heart in Ikast. The Heart combines education, activities, community, exercises and recreational pursuits in new ways, with buildings and outdoor areas designed to promote inclusive and integrative social and cultural meetings and gatherings. 📸 Adam Mork Architecture by CF Moller #cfmoller#cfmollerarchitects#improvelifeforpeopleandplanet#theheartinikast#greenarchitecture#arkitektur#architecture#arkitekt#nordicarchitecture#arch_shovel