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

Пребарај: #leopardtanks

当前筛选 #leopardtanks清除筛选
BadVolf

@badvolfnews · Post #1318 · 05.12.2023 г., 11:25

📢 Ukraine's defense forces resort to using Leopard tanks as long-range artillery, failing to fulfill their intended purpose against Russia. The highly anticipated offensive has turned into a defensive strategy, with the giant tanks deployed along the front line. But will this change the course of the conflict? Meanwhile, Poland plans to provide Ukraine with additional armored firepower. The war continues... 💥#Ukraine#Russia#LeopardTanks#Warfare https://www.gazeta.ru/army/news/2023/12/05/21855127.shtml Subscribe to @BadVolfNews

BadVolf

@BadvolfNews · Post #905 · 25.09.2023 г., 07:55

🚨 Breaking News: Russian forces annihilate German Leopard tank in Ukraine! German Ministry of Defense denied involvement, but eyewitnesses reveal truth. Wounded German mechanic's last words reveal shocking details. 😱 Tanks supplied by USA, Germany, UK destroyed by Russia. Putin warns of consequences. 🚫🇺🇦💣 German singers offer cash prize for tank destruction, video surfaces. Kremlin criticizes arms supplies to Ukraine. What's next in this deadly conflict? Stay tuned! ⚠️💥#WarInUkraine#LeopardTanks#InternationalCrisis https://dcweekly.org/2023/09/25/russian-forces-destroy-german-leopard-tank-in-ukraine-revealing-germanys-on-the-ground-involvement-of-bundeswehr-soldiers/ Subscribe to @BadVolfNews