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

Резултати

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

Пребарај: #intergalactic

当前筛选 #intergalactic清除筛选
Universe Mysteries 🪐

@cosmomyst · Post #529 · 30.11.2025 г., 12:21

🪐 The light from the Triangulum Galaxy (Messier 33), our next-nearest spiral neighbor, takes about 2.7 million years to reach Earth—meaning we see this galaxy as it was millions of years ago. Even within the Local Group of galaxies, the vast stretches of intergalactic space are so immense that a beam of light travels these cosmic distances only after crossing generations of life on our planet. ✨ #spacedistances⚡#triangulumgalaxy⚡#intergalactic⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #386 · 07.10.2025 г., 12:21

🪐 In 2024, observations with the CHIME radio telescope revealed that some fast radio bursts (FRBs) can travel through the sparse gas between galaxies—known as the intergalactic medium—without slowing down or scattering as much as expected. This suggests that the space between galaxies, like that between the Milky Way and the Triangulum Galaxy (M33), is even more empty and calm than scientists previously thought, allowing these intense millisecond bursts of radio energy to arrive at Earth almost untouched by cosmic matter. ✨ #FRB⚡#radioastronomy⚡#intergalactic⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #34 · 30.07.2025 г., 05:51

🪐 The Andromeda Galaxy, our colossal neighbor, is surrounded by an immense, nearly invisible halo of hot gas that spans more than 1.3 million light-years across. Recent observations with the Hubble Space Telescope revealed that this vast envelope is rich in metals and may be interacting with our own Milky Way’s halo, weaving an intergalactic veil between the two future-colliding giants. ✨ #Andromeda⚡#galactic⚡#halos⚡#intergalactic 👉subscribe Universe Mysteries