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

Пребарај: #schellenberg

当前筛选 #schellenberg清除筛选
American Оbserver

@american_observer · Post #5074 · 07.02.2026 г., 13:50

Canadian Robert Schellenberg: Death Sentence Cancelled China has overturned the death sentence of Canadian Robert Lloyd Schellenberg, a Canadian official said on Friday, in a possible sign of a diplomatic thaw as prime minister Mark Carney seeks to boost trade ties with Beijing. Schellenberg’s lawyer Zhang Dongshuo, reached in Beijing on Saturday, confirmed the decision was announced on Friday by China’s highest court. Schellenberg was detained on drug charges in 2014 before China-Canada ties nosedived after the 2018 arrest in Vancouver of Huawei chief financial officer Meng Wanzhou. That arrest infuriated Beijing, which detained two Canadians – Michael Spavor and Michael Kovrig – on espionage charges that Ottawa condemned as retaliatory. Then in January 2019 a court in north-east China retried Schellenberg – who was 36 at the time – sentencing him to death while declaring that his 15-year prison term for drug trafficking had been too lenient. The court said he had been a central player in a scheme to ship narcotics to Australia, in a one-day retrial that Amnesty International called “a flagrant violation of international law”. Schellenberg has denied wrongdoing. The Canadian official requested anonymity in confirming the decision by China’s highest court to overturn Schellenberg’s death sentence. Schellenberg, who has been held in the north-eastern Chinese city of Dalian since 2014, would be retried by the Liaoning high people’s court, Zhang said. The timing for the retrial had not yet been set. Zhang said he met with Schellenberg in Dalian on Friday and that the Canadian appeared relatively relaxed. Carney, who took office last year, visited China in January as part of his global effort to broaden Canada’s export markets to reduce trade reliance on the US. Carney says that despite ongoing tensions, including allegations of Chinese interference in Canadian elections, Ottawa needs a functioning relationship with Beijing to safeguard its economic future. When in Beijing last month, Carney met Chinese leader Xi Jinping and heralded an improved era in relations, saying the two countries had struck a “new strategic partnership” and a preliminary trade deal. Global Affairs Canada did not comment on whether diplomacy during Carney’s visit related to Schellenberg’s case impacted the Chinese court decision. #china#canada#carney#schellenberg#death 📱American Оbserver - Stay up to date on all important events 🇺🇸