@doniyorieltss · Post #2131 · 30.08.2024 г., 14:35
When you dream up your perfect life, you think about how you're seen, rather than what your daily tasks include 101 essays that will change the way you think #insights
Hashtags
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
Пребарај: #insights
@doniyorieltss · Post #2131 · 30.08.2024 г., 14:35
When you dream up your perfect life, you think about how you're seen, rather than what your daily tasks include 101 essays that will change the way you think #insights
Hashtags
@doniyorieltss · Post #2130 · 29.08.2024 г., 14:35
You are more in love with ideas than you are with work and processes required to make them reality 101 essays that will change the way you think #insights
Hashtags
@doniyorieltss · Post #2126 · 28.08.2024 г., 14:35
If you don't know what to do, you don't know what's wrong. If you don't know what's wrong, it is because some part of you is resisting seeing it 101 essays that will change the way you think #insights
Hashtags
@doniyorieltss · Post #2125 · 19.08.2024 г., 14:36
Clarity comes from doing, not thinking about doing 101 essays that will change the way you think #insights
Hashtags
@doniyorieltss · Post #2124 · 18.08.2024 г., 14:35
The best things will not make sense - not initially, at least 101 essays that will change the way you think #insights
Hashtags
@doniyorieltss · Post #2123 · 17.08.2024 г., 14:35
To fully accept your life - the highs, lows, good, bad - is to be grateful for all of it, and to know that the "good" teaches you well, but the "bad" teaches you better 101 essays that will change the way you think #insights
Hashtags
@doniyorieltss · Post #2122 · 16.08.2024 г., 14:34
Sometimes the way light enters us is, in fact, through the wound 101 essays that will change the way you think #insights
Hashtags
@doniyorieltss · Post #2121 · 15.08.2024 г., 14:34
What you learn and who you become is more important than how you temporarily feel 101 essays that will change the way you think #insights
Hashtags
@doniyorieltss · Post #2120 · 14.08.2024 г., 14:34
The people who were able to hurt you most were also the people whom you were able to love the most 101 essays that will change the way you think #insights
Hashtags
@doniyorieltss · Post #2118 · 13.08.2024 г., 14:36
The road to hell was paved with good intentions 101 essays that will change the way you think #insights
Hashtags
@doniyorieltss · Post #2117 · 12.08.2024 г., 14:44
Defensiveness is born of fear; assertiveness is born of confidence 101 essays that will change the way you think #insights
Hashtags
@doniyorieltss · Post #2116 · 11.08.2024 г., 14:34
Life isn't about being "certain", it's about trying anyway 101 essays that will change the way you think #insights
Hashtags