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

Пребарај: #nationalday

当前筛选 #nationalday清除筛选
Embassy of Russia in Singapore

@rusembsg · Post #3154 · 12.06.2024 г., 02:08

On June 11, 2024, Russian Embassy in Singapore hosted a state reception dedicated to the #NationalDay of the Russian Federation – Russia’s Day. Minister of State for Culture, Community and Youth, Minister of State for Trade and Industry, H.E. Mr. Alvin Tan attended the function as the Chief Guest. Among the guests were Members of the Parliament of Singapore, eminent representatives of business and social, scientific and cultural community, mass media along with Ambassadors and Military Attaches of foreign states and Russian compatriots. In his welcoming speech, Ambassador stressed that Russia remembers and appreciates that Singapore and other ASEAN countries were among the first to recognize the new Russia. He stated that thanks to this step, we have the opportunity today to look together into the face of the emerging new, fair, multipolar world. Ambassador continues mentioning that “even though large distances separate us, even though the natural and geographical conditions in which we have to live vary, even though we have different views with Singapore on the parameters of regional architecture and the genesis of the events in Ukraine, there is something very significant that connects us and is the subject of our common daily concerns”. “This connecting link is the mutual concern about the threats created by the arms race and the prospect of its spreading into outer space! This connecting link remains the common resistance to the dangers created by terrorism, transnational crime and the money laundering schemes that feed them! We rightfully consider our devotion to the ideals of building a drug-free world to be this connecting link! We consider our common efforts to guarantee international information security to be this connecting link, which would securely block the destructive use of the information environment! And finally, closer to the venue of our meeting today, we see such a link in cooperation for building an open and inclusive, free, predictable region based on the inviolable principles of ASEAN centrality”, he noted. “We invite you to take a closer look at the concept of the Greater Eurasian Partnership that we are promoting and to join the triptowards a new, common and indivisible formula for security in Asia and the Pacific as an alternative to conflicting Indo-Pacific concepts of the collective West. I am convinced that our cooperation has a bright future. It should contribute to the creation of a new world community free from the remnants of colonialism”, concluded the Ambassador.

Hashtags

聖小熊的秘密基地 🇹🇼

@holybeartw · Post #1213 · 10.10.2025 г., 10:18

🇹🇼 祝大家國慶連假快樂!🇹🇼 中華民國屹立於台灣之島,雖身處天災頻發與地緣緊張的前線,一路以來戰戰兢兢、克服一切困難。 我們或許時有歧見與爭論,然而「團結」始終是這片土地上最堅韌而無畏的力量。願我們在相互理解與信任之中,持續邁向更具包容與希望的社會。 中華民國台灣萬歲! #NationalDay#ROC#Taiwan