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

Пребарај: #upgradeyourride

当前筛选 #upgradeyourride清除筛选
Auto Life

@revheadcrypto · Post #604 · 26.10.2024 г., 14:26

🚗✨Unleashing Power: Audi SQ8 Tuned by ABT!✨🚗 The ABT tuning atelier has taken the Audi SQ8 to new heights! 🚀 With a powerful 4.0-liter V8 engine, it now boasts an impressive 650 HP and 850 Nm of torque—just 10 HP shy of the factory RS Q8! 💪 This comprehensive upgrade package, priced at €35,500, includes: • Stunning aerodynamic body enhancements 🛠️ • Carbon interior accents 🌟 • Eye-catching 23-inch wheels 🏎️ • A lowered ride height by 25mm for that sporty look! 🔥 #AudiSQ8#ABT#Tuning#LuxuryCars#Performance#CarEnthusiast#UpgradeYourRide#Auto

Auto Life

@revheadcrypto · Post #391 · 26.08.2024 г., 20:00

🚗✨ Introducing the New Techart Aero Kit I for the Updated Porsche Cayenne! ✨🚗 Get ready to elevate your ride with this stunning aerodynamic body kit that not only enhances the aggressive look of the Cayenne but also improves its aerodynamics! 💨🔥 While the price of the kit is yet to be announced, Techart is already working on even more aggressive versions to take your driving experience to the next level! 🚀💪 #Techart#PorscheCayenne#AeroKitI#CarEnthusiast#LuxuryCars#Aerodynamics#UpgradeYourRide#Auto