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

Пребарај: #mentalgrowth

当前筛选 #mentalgrowth清除筛选

Hard work is a must thing for success. Smart work is not a substitute for hard work, it is another wing of the bird which can take you to your success. In short, there is no substitute for hard work! You have to be ready for it. Put everything you have for what you want, This is the way of massive success! Problems are going to be there always! Tackle them. You have only two choices, one is EXCUSES and other is RESULTS. The choice is yours! Don’t sacrifice your dreams for temporary pleasure. Neither this pleasure is going to come with you nor this pain. Choose temporary pain for your permanent happiness. ⭐️ Give your 100% (not even 99%) for your dreams! Don’t run away from hard work. Thisis going to give you your dreams! ✨💪 #mentalGrowth#ipersonalgrowths#smarwork#hardwork

Fear or opportunity? Fears are the body's adequate reaction to something new, to something that once caused unpleasant consequences, or to something that directly or indirectly threatens one's life. But there are fears that simply must be overcome. For example, if you have an idea, but to implement it, you do not have the courage, and therefore and perseverance. It is behind such fears that lies your invaluable potential. The body never generates ideas that it doesn't have the resources to implement. Our thoughts are not random. Think of the opportunities that will open up before you after you overcome your fear. Have you imagined it? Now act! Join us for more -> @ipersonalgrowths💡 #MentalGrowth #Fear #opportunity #psychologyinformation