@sgmrt · Post #1425 · 01.04.2022 г., 04:41
[CCL] CLEARED: Train services between #Stadium and #Bartley have resumed. Free regular bus & free bridging bus svcs have ended. - SMRT
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
Пребарај: #bartley
@sgmrt · Post #1425 · 01.04.2022 г., 04:41
[CCL] CLEARED: Train services between #Stadium and #Bartley have resumed. Free regular bus & free bridging bus svcs have ended. - SMRT
@sgmrt · Post #1421 · 01.04.2022 г., 04:09
[CCL]: Shuttle train service is available between #Stadium and #Bartley Platform B. - SMRT
@sgmrt · Post #1422 · 01.04.2022 г., 04:09
[CCL] UPDATE: Additional 30mins train travel time between #Stadium and #Bartley due to a train fault. Free regular bus and bridging bus services between #Promenade and #Serangoon are available. - SMRT
@sgmrt · Post #1420 · 01.04.2022 г., 03:52
[CCL] Additional 20mins train travel time between #Stadium and #Bartley due to a train fault. Free regular bus services between #Promenade and #Serangoon are available. - SMRT
@sgmrt · Post #2278 · 05.03.2025 г., 08:54
[CCL]: Train services are progressively returning to normalcy. Please add 5 mins of additional travelling time between #Promenade and #Serangoon in both directions. Free regular bus services are available between #Promenade and #Serangoon. Shuttle train service will cease between #Bartley and #Mountbatten. - SMRT
@sgmrt · Post #2277 · 05.03.2025 г., 08:44
[CCL]: Due to a train fault, please add 30 mins of additional travelling time between #Promenade and #Serangoon in both directions. Free regular bus services are available between #Promenade and #Serangoon. Shuttle train service is available between #Bartley and #Mountbatten. - SMRT
@sgmrt · Post #2275 · 05.03.2025 г., 08:24
[CCL]: Due to a train fault, please add 30 mins of additional travelling time between #Promenade and #Serangoon in both directions. Free regular bus services are available between #Promenade and #Serangoon. Shuttle train service is available between #Bartley and #Mountbatten. - SMRT