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

Пребарај: #contents

当前筛选 #contents清除筛选
Quiet World 🍁

@QuietWorld · Post #6661 · 07.10.2019 г., 13:00

Sometimes, I scrolled back to my previous #thoughts posts so that I can reread and remember what I said to myself to calm myself down & to assure that I can cope, so that I can cope again & again & again – & this is the main reason I started this channel last year & I'm glad I did, although I started to quite neglect it a lot this year 🥺 & I'm thankful for those of you who subscribed and stayed in this channel, especially those who responded to my #poll, interacted with us through our @qw_qwbot, & view our posts, because tbh it makes me feel like there's someone 'listening' to me and that is enough and much appreciated ❤ Thanks dear subscribers. Anyway, just for the update, we only have two admins now; Conan & me, but Conan seems to be occupied with his work since he started working this year, so because of those two reasons mentioned earlier, there might be less frequent posts in this channel 😅 But worry not, because we'll still be providing you with the best #contents we can 🤗 As for the new subscribers, welcome! 🥰🥳 #channelupdate#chupdate @quietworld🍃

Tg Links

@TgDict · Post #9 · 09.03.2021 г., 11:27

#Start#contents#index#mark This channel publishes groups and channels according to a main directory and several subject sub-directories for index search The search keywords are as follows: One type of keywords: Nine categories of first-level keywords Two types of keywords: Second-level keywords + geographic region + language family 1. Telegraph #telegram#Promotion #Group#channel#robot #Search#index#navigation 2. Resources #Resources#Share #Sharing#Welfare#moive#music#Books 3. Broadcasting #Broadcasting #message#info#news#blog 4. Chat category #Chat #chitchat#communication#city#area #Chinese#English#language#country #Mainland#HongKong#Taiwan 5. Computer category #Computer #Hardware#software#VPN#programming 6. Life category #life #Entertainment#Game#Funny#Anime #Live#tourism 7. Subjects #Subjects #Interest#hobbies#topic 8.Industry #Industry#business 9.To be classified #notes Unclassified