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

Резултати

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

Пребарај: #bennu

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

@cosmomyst · Post #25 · 30.07.2025 г., 01:00

🪐 In the constellation Ophiuchus, the asteroid 101955 Bennu harbors boulders on its surface that are actually fragments from a much larger parent asteroid, dislodged by ancient cosmic impacts. Analysis of samples returned by NASA’s OSIRIS-REx mission revealed minerals that interacted with liquid water billions of years ago, revealing Bennu as a time capsule from the dawn of the solar system. ✨ #Bennu⚡#asteroids⚡#OSIRISRex 👉subscribe Universe Mysteries

Universe Mysteries 🪐

@cosmomyst · Post #338 · 27.09.2025 г., 18:21

🪐 One of the most intriguing potentially hazardous asteroids is (101955) Bennu, a 500-meter-wide space rock that approaches Earth every six years. Bennu's orbit is so well-studied that NASA sent the OSIRIS-REx mission to collect samples, as even small forces—like sunlight changing its spin—can alter its path, making Bennu a prime real-world example of why scientists keep a close watch on these cosmic wanderers. ✨ #asteroids⚡#hazard⚡#Bennu⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #290 · 18.09.2025 г., 09:40

🪐A skyscraper-sized space rock is on its way past Earth. On September 18, 2025, asteroid 2025 FA22, measuring up to 300 meters across, will sweep by our planet. At its closest, it will be about 835,000 km away — more than twice the distance to the Moon. Moving at a breathtaking 34,000 km/h, this Apollo-type asteroid silently follows its orbit around the Sun, crossing Earth’s path in space. The flyby will peak around 07:41 UTC, a moment astronomers worldwide are watching closely. Massive, fast, and ancient — yet passing safely by. Encounters like this remind us how close cosmic giants can come, while still leaving Earth untouched. ✨ #asteroids⚡#hazard⚡#Bennu⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries

Universe Mysteries 🪐

@cosmomyst · Post #231 · 06.09.2025 г., 13:11

🪐 The asteroid Bennu, about 500 meters wide, orbits the Sun and regularly passes close to Earth—so close that it’s classified as a “potentially hazardous asteroid.” Scientists continually monitor Bennu’s path because even small shifts caused by sunlight (known as the Yarkovsky effect) could alter its future trajectory, making it one of the most closely watched objects to help protect our planet from possible impacts. ✨ #asteroid⚡#hazards⚡#Bennu⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries ​

Universe Mysteries 🪐

@cosmomyst · Post #432 · 16.10.2025 г., 15:21

🪐 One of the closest ongoing space threats to Earth is asteroid (101955) Bennu, a 500-meter-wide rock whose orbit brings it near our planet about every six years. Bennu's path is carefully tracked because even small gravitational nudges or sunlight (the Yarkovsky effect, where heat causes tiny pushes) could change its future route, making it a real-world example of why scientists keep a vigilant watch on these near-Earth objects. ✨ #asteroids⚡#defense⚡#Bennu⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​