@trading_pit_signal · Post #34124 · 08.02.2024 г., 14:42
Remember to share team keep motivating. #Screenshot those Blue blizzards we going for more TP's MORE FEEDBACK MORE SIGNALS
Hashtags
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
Пребарај: #screenshot
@trading_pit_signal · Post #34124 · 08.02.2024 г., 14:42
Remember to share team keep motivating. #Screenshot those Blue blizzards we going for more TP's MORE FEEDBACK MORE SIGNALS
Hashtags
@trading_pit_signal · Post #33919 · 06.02.2024 г., 07:21
Remember to share FEEDBACK team keep motivating. #Screenshot those Blue blizzards we going for more TP's MORE FEEDBACK MORE SIGNALS
Hashtags
@trading_pit_signal · Post #33602 · 31.01.2024 г., 14:14
You can see gold🔥 and currency pairs 🔥 This is how it's done guys. #Screenshot your profit and send to admin. Click on the pinned message and contact admin
Hashtags
@trading_pit_signal · Post #33601 · 31.01.2024 г., 14:14
You can see gold🔥 and currency pairs 🔥 This is how it's done guys. #Screenshot your profit and send to admin. Click on the pinned message and contact admin
Hashtags
@trading_pit_signal · Post #33599 · 31.01.2024 г., 14:13
You can see gold🔥 and currency pairs 🔥 This is how it's done guys. #Screenshot your profit and send to admin. Click on the pinned message and contact admin
Hashtags
@trading_pit_signal · Post #33598 · 31.01.2024 г., 14:07
Remember to share FEEDBACK team keep motivating. #Screenshot those Blue blizzards we going for more TP's MORE FEEDBACK MORE SIGNALS
Hashtags
@trading_pit_signal · Post #33552 · 31.01.2024 г., 08:59
You can see gold🔥 and currency pairs 🔥 This is how it's done guys. #Screenshot your profit and send to admin. Click on the pinned message and contact admin
Hashtags
@trading_pit_signal · Post #33550 · 31.01.2024 г., 08:56
You can see gold🔥 and currency pairs 🔥 This is how it's done guys. #Screenshot your profit and send to admin. Click on the pinned message and contact admin
Hashtags
@trading_pit_signal · Post #33537 · 31.01.2024 г., 07:38
Remember to share FEEDBACK team keep motivating. #Screenshot those Blue blizzards we going for more TP's MORE FEEDBACK MORE SIGNALS
Hashtags
@trading_pit_signal · Post #33493 · 30.01.2024 г., 12:53
You can see gold🔥 and currency pairs 🔥 This is how it's done guys. #Screenshot your profit and send to admin. Click on the pinned message and contact admin
Hashtags
@trading_pit_signal · Post #33491 · 30.01.2024 г., 12:52
You can see gold🔥 and currency pairs 🔥 This is how it's done guys. #Screenshot your profit and send to admin. Click on the pinned message and contact admin
Hashtags
@trading_pit_signal · Post #33487 · 30.01.2024 г., 12:45
Remember to share team keep motivating. #Screenshot those Blue blizzards we going for more TP's MORE FEEDBACK MORE SIGNALS
Hashtags