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

Резултати

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

Пребарај: #cosmicmicrowavebackground

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

@cosmomyst · Post #317 · 23.09.2025 г., 15:21

🪐 The cosmic microwave background reveals a subtle "axis of evil"—a strange alignment of temperature fluctuations stretching across the entire sky, first noticed in WMAP and confirmed by Planck. This odd pattern challenges the idea that the universe is the same in every direction, and scientists are still exploring whether it's a real feature or a cosmic coincidence hidden in the oldest light we can see. ✨ #cosmicmicrowavebackground⚡#universe⚡#symmetry⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #551 · 11.12.2025 г., 12:21

🪐 The cosmic microwave background holds a hidden fingerprint—tiny temperature fluctuations mapped in exquisite detail by satellites like Planck reveal how the first stars and galaxies, such as those in the ancient cluster Abell 2744, grew from initial small ripples in the early universe. These faint variations, just millionths of a degree, became the seeds around which all the cosmic structures we see today first assembled. ✨ #cosmicmicrowavebackground⚡#earlyuniverse⚡#galaxyclusters⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #355 · 30.09.2025 г., 22:21

🪐 Stretching across all of space, the cosmic microwave background is sprinkled with mysterious "hot" and "cold" rings—subtle patterns first mapped by the Planck satellite. One of these ring structures, dubbed the "CMB rings," shows up as smooth, circular features and could be the leftover imprint of massive waves moving through the young universe, giving scientists a unique window into the conditions just hundreds of thousands of years after the Big Bang. ✨ #cosmicmicrowavebackground⚡#earlyuniverse⚡#planck⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​