@QuietWorld · Post #6675 · 10.10.2019 г., 00:00
Fair play isprimarilynot blaming others for anything that is wrong with us. — Eric Hoffer – #quotes#truth#selfdevelopment @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
Пребарај: #selfdevelopment
@QuietWorld · Post #6675 · 10.10.2019 г., 00:00
Fair play isprimarilynot blaming others for anything that is wrong with us. — Eric Hoffer – #quotes#truth#selfdevelopment @quietworld🍃
Hashtags
@englishmeta1 · Post #94 · 14.03.2022 г., 08:51
Learn to refuse! Such a skill can be useful to get away from pressure and extortion from manipulators, especially if you are a soft, compliant person and are afraid to refuse someone, even at the cost of your own comfort and peace of mind. Start with a softer option: “I don’t think”, “I won’t succeed”, “I can’t”. To begin with, it is important to understand that there is the very possibility of failure, then it will become easier. But in the end, you need to come to a firm “no” without explaining your refusal or justifying your decision to others. *** Next post: Life Tips ♡ ㅤ ⎙ㅤ ⌲ 🔔 ˡᶦᵏᵉ ˢᵃᵛᵉ ˢʰᵃʳᵉ unmute #psychology#Selfdevelopment 📝 Requests: @Guidancee_bot ©@This_is_psychology
Hashtags
@QuietWorld · Post #6683 · 10.10.2019 г., 09:30
Often we change..; jobs, friends and spouses.. instead of ourselves. — Akbarali H. Jetha – #quotes#reflection#selfdevelopment @quietworld🍃