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

Резултати

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

Пребарај: #lamcheukting

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

@hkdmovement · Post #7918 · 18.12.2024 г., 03:55

在元朗襲擊事件五年後,前立法會議員林卓廷及其他六名被告今日(12日)在區域法院被裁定暴動罪成。法官陳廣池的判決引發爭議,他被指出故意改變事件敘述,將受害者置於不利地位,將他們送入監獄。 林卓廷在事件中履行自己的職責,努力了解警方為何未能及時出現,並未違法。然而,法官的判決卻顯示出其腐敗,似乎受到中國共產黨的影響,從上到下違反法律。 這一判決不僅是對受害者的不公正對待,更是對法治的嚴重挑戰。 #721裁決#林卓廷#暴動罪#不公正#法治危機 After five years since the Yuen Long attack, former Legislative Council member Lam Cheuk-ting and six co-defendants have been found guilty of riot charges today (12th) in the District Court. Judge Chan Kwong-chi's ruling has sparked controversy, with accusations that he deliberately altered the narrative to put the victims behind bars. Lam Cheuk-ting was doing his job by seeking to understand why the police did not respond in a timely manner and acted within the law. However, the judge's decision reveals corruption influenced by the Chinese Communist Party, breaking the law from top to bottom. This ruling not only represents an injustice to the victims but also poses a severe threat to the rule of law. #721Verdict#LamCheukting#Injustice#RuleOfLaw