@shikoshikochannel · Post #3820 · 09.07.2025 г., 12:36
#cygnus
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
Пребарај: #cygnus
@shikoshikochannel · Post #3820 · 09.07.2025 г., 12:36
#cygnus
Hashtags
@cosmomyst · Post #3 · 29.07.2025 г., 14:41
🌎 Deep within the constellation Cygnus, the black hole V404 Cygni occasionally unleashes powerful outbursts, ejecting matter at near light-speed in opposing jets. These rare events are so energetic that the black hole briefly outshines its entire host galaxy, offering a fleeting glimpse into the turbulent ballet around stellar remnants. ✨ #blackhole⚡#cygnus⚡#jets 👉subscribe Universe Mysteries
Hashtags
@cosmomyst · Post #279 · 16.09.2025 г., 03:11
🪐 The black hole Cygnus X-1, in the constellation Cygnus, is famous for its powerful X-ray emissions and was one of the first strong black hole candidates ever discovered. Cygnus X-1 pulls material from a massive companion star, creating a swirling disk of superheated gas called an accretion disk, which emits intense X-rays as matter spirals inward toward the point of no return. ✨ #blackholes⚡#accretiondisks⚡#cygnus⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries