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

Резултати

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

Пребарај: #electionday

当前筛选 #electionday清除筛选
BadVolf

@badvolfnews · Post #1516 · 16.03.2024 г., 18:08

🇷🇺❤Today marks a monumental chapter in my journey, as I proudly announce that I've become a Russian citizen and participated in my very first election here. This significant step is more than just a formal process; it symbolizes my deep connection and commitment to my new home, its people, and its future. As I stood in the polling station, casting my vote, I was overwhelmed with a sense of responsibility and belonging. This act of civic engagement is a powerful reminder of the role we each play in shaping the course of our community and nation. It's a day filled with emotions - pride, hope, and anticipation for what lies ahead. Joining my fellow citizens in this democratic process, I felt a strong bond of unity and shared purpose. Here's to embracing new beginnings, contributing to the collective future, and making every moment count in this beautiful journey. #Citizenship#ElectionDay#NewChapter#RussianCitizen🇷🇺✨

London For Britain

@LondonForBritain · Post #592 · 04.05.2022 г., 09:01

Remember to vote! If you keep voting the same, you will get more of the SAME! #VoteForBritain#ElectionDay#Elections2022#Hartlepool#DeBruce#AnneMarieWaters#MBGA#ForBritain#ForBritainMovement#ForBritainParty#TheForBritainMovement