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

Пребарај: #xrays

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

@cosmomyst · Post #176 · 23.08.2025 г., 03:11

🪐 In the galaxy NGC 300, astronomers identified the black hole NGC 300 X-1 locked in a close dance with a massive Wolf-Rayet star—an extremely hot, luminous star that is rapidly shedding its outer layers. As the black hole pulls matter from its companion, powerful X-rays are released, creating a system where each orbit peels more material from the star and reveals how black holes can dramatically alter the life and fate of their stellar partners. ✨ #blackholes⚡#xrays⚡#ngc300⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries ​

Universe Mysteries 🪐

@cosmomyst · Post #530 · 30.11.2025 г., 22:21

🪐 The magnetar 1RXS J170849.0–400910, located about 18,000 light-years away in the constellation Ophiuchus, is known for its titanic magnetic field, which can reach over 100 trillion times the strength of Earth's. This intense magnetism is so powerful that it can twist the star's crust, triggering sudden bursts of X-rays and gamma rays—brief flashes that outshine entire regions of space before fading into darkness. ✨ #magnetar⚡#Xrays⚡#Ophiuchus⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​