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

Резултати

Пронајдени 22 слични објави

Пребарај: #positivity

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

@QuietWorld · Post #6627 · 02.10.2019 г., 03:53

It's an absolutely naive to say or think that humans are perpetually happy. Even the most positive person will meet his own dark side. Everyone has a shadow; toxic positivity is the recipe to create thick, dense shadow – because you must always wear the mask of happiness to hide other negative emotions and kick them into unconsciousness until it rots and fester into a monster that will come to the surface when you least expect it. Remember that positivity is not about pretending and not about happiness – it's a mindset; it's about assessing the situation, accepting and understanding your feelings and looking to see if there's anything you can do to make the most of the situation. 🤗 Source: Einzelganger & Positively Present #positivity#selfreminder @quietworld🍃

Quiet World 🍁

@QuietWorld · Post #7241 · 29.03.2020 г., 08:12

Today, Tomorrow or Yesterday? You can't avoid conflicts or problems. In fact, they're ESSENTIAL parts of life. Live today. If you worry about what may go wrong in the future, it might not even happen anyway 🤷🏻‍♀. If you keep on thinking about the past, there's no way to bring you back to the past🙍🏻‍♀. It's okay to look into the future to plan, but not okay to simply worry. It's okay to look back in the past and reflect, but it's not okay to stay stucked in the past. Live. Today. 😊 #life#reminder#positivity @quietworld🍃

Quiet World 🍁

@QuietWorld · Post #6626 · 02.10.2019 г., 03:53

"Positive vibes only 🌸" - oh really? good luck with that! I've been using the word positivity and shared lots of positivity quotes – little that I know that the word 'positivity' can mean differently to different people. So, if you haven't heard it yet, let me introduce you to Toxic Positivity – in which I've also been guilty of at times too🥺 Toxic positivity encourages ignoring negative emotions, but true positivity is about accepting all emotions and doing whatever is possible to work through them, understand them and garner more self-awareness. Toxic positivity presents itself as something anyone can do at any time, but positivity is actually a mindset that doesn't often come easily & must be worked at for most people - IT'S A SKILL. In short, toxic positivity is an attempt to force happiness by rejecting any form of undesirable aspect of an event - but be aware that rejecting either good or bad is similar to rejecting 50% of the universe, because the world isn't good vibes only, it's just vibes. I hope these provide you with a clear understanding of what is toxic positivity and what's true positivity is - and in case you need more clarity, I'd post a few more quotes related in my next posts. 😉 Source: Positively Present & Einzelganger #positivity#afterthoughts#selfreminder @quietworld🍃

12
ПретходнаСтраница 1 од 2Следна