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

Пребарај: #uselections

当前筛选 #uselections清除筛选
Hong Kong Democracy Movement

@hkdmovement · Post #7914 · 29.11.2024 г., 11:06

美國國會屬下的「美中經濟暨安全檢討委員會」(USCC)於周二(19日)向國會提交2024年報告,涵蓋中美經貿關係、台灣及香港等議題。報告指出,《基本法》23條的立法進一步為港府提供打壓異見的法律工具,香港的法治正受到威脅,法院隨23條的實施被武器化,甚至成為協助俄羅斯等國逃避制裁的中轉站。 #23條立法#USCC#中美角力#美國大選 On Tuesday (19th), the U.S.-China Economic and Security Review Commission (USCC) submitted its 2024 report to Congress, addressing U.S.-China economic relations, Taiwan, and Hong Kong. The report mentions that the implementation of Article 23 of the Basic Law provides the Hong Kong government with legal tools to suppress dissent, threatening the rule of law. It also asserts that Hong Kong has become a transit point for aiding countries like Russia in evading sanctions. #Article23#USCC#USChinaTensions#USElections

Freedom Flotilla Coalition

@FFC_official_channel · Post #224 · 31.08.2024 г., 23:58

This election is not just about what happens within U.S. borders—it’s about the lives of millions around the globe. When you vote, you’re making a statement about where America stands on human rights. History has shown us that you cannot negotiate with leaders who offer nothing but empty promises. Kamala Harris herself said, "Never let anyone tell you who you are. Show them who you are." Well, the Biden-Harris administration has shown us who they are. For ten months, they’ve done nothing but fund the annihilation of Gaza and the West Bank. We cannot accept these empty words when hundreds of thousands of lives are at risk. It’s time to demand real action, not just lip service. Sign the petition to enact an arms embargo on Israel, spread the truth in your community, and mobilize for the sake of humanity. Take Action Now: 🖋️ Sign the Petition: Not Another Bomb! Demand an arms embargo to stop the genocide (in our stories) 📰 Stay Informed: Join the Uncommitted Movement and tell Kamala Harris to stand on the right side of history. Sign up for updates. 🗣️ Spread the Word: Distribute flyers, educate your community, and support candidates who truly stand for human rights. #KillerKamala#BidenHarris#USElections#DNC#ActForGaza#EndTheOccupation#NoMoreEmptyPromises#FreeGaza#FreePalestine#PermanentCeasefire#UNSecurityCouncil#GlobalImpact#FFC#FreedomFlotilla