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

Пребарај: #capitolriots

当前筛选 #capitolriots清除筛选
Reuters: World

@reutersworldchannel · Post #149353 · 14.10.2021 г., 13:16

October 14, 2021: Norway mass killing, Taiwan fire, Big Tech, U.S. Capitol riots, California October 14, 2021: Norway mass killing, Taiwan fire, Big Tech, U.S. Capitol riots, California 1. A 37-year-old Danish citizen who had converted to Islam is suspected of killing five people with a bow-and-arrow and other weapons in the Norwegian town of Kongsberg in a rare incident of mass killing in Norway, police said. 2. A fire in a residential building in the southern Taiwanese city of Kaohsiung has killed 46 people and injured another 41, the government said. 3. A bipartisan group of lawmakers, headed by Democrat Amy Klobuchar and Republican Chuck Grassley, plan to introduce a bill that would bar Big Tech platforms, like Amazon and Google, from favoring their products and services. 4. A congressional panel investigating the deadly Jan. 6 riot at the U.S. Capitol said it has issued a subpoena seeking testimony and records from Jeffrey Clark, a former senior official at the Justice Department who was a proponent of former President Donald Trump's false election fraud claims. 5. California firefighters took advantage of a break in strong winds to get an aircraft aloft and dump retardant on a fast-moving wildfire that was within a half mile of former President Ronald Reagan's ranch, officials said. #Norway #Taiwan #Fire #BigTech #Democrats #Republicans #AmyKlobuchar #ChuckGrassley #UnitedStates #CapitolRiots #Trump #California #Wildfires #RonaldReagan #News #Reuters Subscribe: http://smarturl.it/reuterssubscribe Reuters brings you the latest business, finance and breaking news video from around the globe. Our reputation for accuracy and impartiality is unparalleled. Get the latest news on: http://reuters.com/ Follow Reuters on Facebook: https://www.facebook.com/Reuters Follow Reuters on Twitter: https://twitter.com/Reuters Follow Reuters on Instagram: https://www.instagram.com/reuters/?hl=en ➖@reutersworldchannel➖