@QuietWorld · Post #6230 · 12.03.2019 г., 07:12
Don’t look back and wonder why things went wrong. Don’t regret not doing more. It happened for a reason. Your better days are ahead of you. #motivation#assurance @quietworld🍃
Hashtags
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
Пребарај: #assurance
@QuietWorld · Post #6230 · 12.03.2019 г., 07:12
Don’t look back and wonder why things went wrong. Don’t regret not doing more. It happened for a reason. Your better days are ahead of you. #motivation#assurance @quietworld🍃
Hashtags
@QuietWorld · Post #6459 · 15.05.2019 г., 04:49
#assurance#selfreminder @quietworld🍃
Hashtags
@QuietWorld · Post #6864 · 05.11.2019 г., 10:23
Two years being passive is just a blink of an eye 😉 Two years moving towards a big goal every single day is plenty of time 😮 There is nothing that cannot be accomplished in two years with enough effort 😎 #life#motivation#assurance @quietworld🍃
Hashtags
@QuietWorld · Post #6231 · 12.03.2019 г., 11:15
“When it comes to breaking old habits and starting new ones, remember to be patient with yourself. You’ve got to expect it’s going to take time and effort before you see lasting results.” #quotes#assurance#motivation @quietworld🍃
Hashtags
@QuietWorld · Post #7195 · 16.02.2020 г., 10:05
#assurance#selfcare#selfreminder @quietworld🍃
Hashtags
@QuietWorld · Post #7359 · 08.06.2020 г., 03:08
to anyone who might need this at this moment🌹 #reminder#selfcare#assurance @quieworld🍃
Hashtags
@QuietWorld · Post #7223 · 21.03.2020 г., 04:07
It is not a sin to be upset; with someone, with a situation, with yourself. Give yourself time to absorb what you're feeling until you're ready to move to where there's growth. #selfreminder#selfcare#assurance#wisdom @quietworld🍃
@QuietWorld · Post #6856 · 04.11.2019 г., 13:33
Appreciate where you are in your journey, even if it's not where you want to be - because every season serves a purpose. #life#quotes#assurance#gratitude#happiness @quietworld🍃
@QuietWorld · Post #7338 · 04.06.2020 г., 15:56
Things to Remember🍃 #thingstoremember#quotes#selfreminder#selfcare#life#assurance @quietworld🍃
@QuietWorld · Post #7341 · 05.06.2020 г., 15:02
#thingstoremember#life#selfcare#selfreminder#assurance#solitude @quietworld🍃