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

Пребарај: #there

当前筛选 #there清除筛选
Social Justice Watch

@social_justice_watch · Post #17089 · 05.09.2022 г., 16:03

i get that people are more comfortable with defined rules and structure but i also think queer people lost when they started resorting to dictionary definitions for what labels mean the queer umbrella is meant to deviate from the norm of rigid boxes and definitions and to decide that lesbian means Only this, bi means Only this, etc, is directly contradicting what queer means. each and every label is going to have a unique meaning to the person using it and that is how it’s supposed to be. if you’re not comfortable with that…sorry? basically if someone tries to tell you you’re using a label wrong: [image description: a set of tumblr tags from @/elinaline, reading: “#there is a way to use a label wrong actually; #its when you force it on someone else”. end image description.] this is the only answer i’ll accept thank u everyone for your participation <3 https://genderkoolaid.tumblr.com/post/689713705918791680

Hashtags

Social Justice Watch

@social_justice_watch · Post #17075 · 05.09.2022 г., 12:49

i get that people are more comfortable with defined rules and structure but i also think queer people lost when they started resorting to dictionary definitions for what labels mean the queer umbrella is meant to deviate from the norm of rigid boxes and definitions and to decide that lesbian means Only this, bi means Only this, etc, is directly contradicting what queer means. each and every label is going to have a unique meaning to the person using it and that is how it’s supposed to be. if you’re not comfortable with that…sorry? basically if someone tries to tell you you’re using a label wrong: [image description: a set of tumblr tags from @/elinaline, reading: “#there is a way to use a label wrong actually; #its when you force it on someone else”. end image description.] this is the only answer i’ll accept thank u everyone for your participation <3 https://genderkoolaid.tumblr.com/post/689713705918791680

Hashtags