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

Пребарај: #modelsai

当前筛选 #modelsai清除筛选
Repositorio data science

@repo_science · Post #3240 · 29.05.2023 г., 15:22

#ChatGPT#modelsAI#freelancer 🤩 Make Money Freelancing with Chatpgpt - Step-by-Step Are you ready to take your freelancing business to the next level with the power of AI? Look no further than “Freelancing Business with AI & Chatgpt – Learn Step-by-step” – the comprehensive course designed to help you succeed in the world of online freelancing. In this course, you’ll learn proven step-by-step strategies for building a profitable freelancing business that harnesses the latest AI technologies. 🔗Link 🔐@repo_science ----- Main channel:@repo_science Coupons:@freecoupons_reposcience -----

Repositorio data science

@repo_science · Post #3241 · 29.05.2023 г., 15:54

#ChatGPT#modelsAI#freelancer#wordPress 🤩 Start Building Money Making Blog with ChatGPT & WordPress Are you interested in starting a blog but don’t know where to begin? Do you want to earn money while doing something you love? Look no further than WordPress, the most popular platform for creating and managing a blog. In this comprehensive course, we’ll guide you through the process of setting up a WordPress blog and show you how to turn it into a money-making machine. Our course, “Start Free Money Making Blogging with ChatGPT & WordPress,” is designed for beginners who want to learn the ins and outs of blogging with WordPress. With over 40% of all websites on the internet using WordPress, it’s clear that this platform is the best choice for creating a successful blog. 🔗Link ----- Main channel:@repo_science Coupons:@freecoupons_reposcience -----