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

Пребарај: #extremespace

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

@cosmomyst · Post #238 · 07.09.2025 г., 20:11

🪐 In the heart of the Milky Way, the magnetar Swift J1818.0−1607 was discovered in 2020 and boasts a magnetic field over a quadrillion (1,000,000,000,000,000) times stronger than Earth's. This incredible power can twist and crack the surface of the magnetar, triggering sudden explosions of X-rays and gamma rays that ripple through space—making magnetars some of the most extreme and mysterious stars known. ✨ #magnetars⚡#neutronstars⚡#extremespace⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries ​

Universe Mysteries 🪐

@cosmomyst · Post #704 · 07.03.2026 г., 22:21

🪐 The magnetar named J1745−2900, discovered near the center of our galaxy close to Sagittarius A*, has one of the most powerful magnetic fields ever measured—enough to disrupt radio signals and, in theory, even deform atoms into thin strings. This type of neutron star is so incredibly magnetic that its field would erase every credit card on Earth from a distance of half the Moon’s span, making J1745−2900 an extreme natural magnet impossible to recreate in any lab. ✨ #magnetar⚡#neutronstar⚡#extremespace⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​