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

Резултати

Пронајдени 56 слични објави

Пребарај: #webdevelopment

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

@repo_science · Post #4002 · 29.01.2024 г., 13:09

#webDevelopment 🌐 Practice It: CSS Layout Get hands-on practice with some of the most powerful CSS features. 🗣 Julia Dyck 🔰 Intermediate ⏰1h 52m ----- Main channel: @repo_science Coupons: @freecoupons_reposcience -----

Repositorio data science

@repo_science · Post #3839 · 02.01.2024 г., 09:26

##webDevelopment 🌐 Next.js & React - The Complete Guide (incl. Two Paths!) Learn NextJS from the ground up and build production-ready, fullstack ReactJS apps with the NextJS framework! 🗣 Maximilian Schwarzmüller ----- Main channel: @repo_science Coupons: @freecoupons_reposcience -----

Repositorio data science

@repo_science · Post #3822 · 26.12.2023 г., 21:02

#webDevelopment 🌐 Next.js & React - The Complete Guide (incl. Two Paths!) Learn NextJS from the ground up and build production-ready, fullstack ReactJS apps with the NextJS framework! 🗣 Maximilian Schwarzmüller ----- Main channel: @repo_science Coupons: @freecoupons_reposcience -----

Repositorio data science

@repo_science · Post #3529 · 22.08.2023 г., 22:57

#webDevelopment 🌐 React: Creating and Hosting a Full-Stack Site Learn how to combine React, Node.js, and Amazon Web Services (AWS) in a full-stack, full-featured website. Author: Shaun Wassell Date: 2022-09-13 Duration: 4h 44m 🔗Link ----- Main channel:@repo_science Coupons: @freecoupons_reposcience -----

Repositorio data science

@repo_science · Post #3384 · 03.07.2023 г., 15:51

#webDevelopment 🥷 Más de 400 iconos SVG Gratis para añadir a tus proyectos. 🔄 Compatibles con Tailwind, React JSX y Figma 📏 Configura su tamaño entre 12px y 48px 🖌️ Configura su contorno entre 0.1 y 3 🔗flowbite.com/icons ----- Main channel: @repo_science Coupons: @freecoupons_reposcience -----

Repositorio data science

@repo_science · Post #3631 · 03.10.2023 г., 03:39

#Python#webDevelopment#Book 🐍 Django 4 for the Impatient. Learn the core concepts of Python web development with Django in one weekend ✍ G. Lim, D. Correa 📆: 2022 ISBN: 9781803245836 ----- Main channel: @repo_science Coupons: @freecoupons_reposcience -----

ПретходнаСтраница 1 од 5Следна