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

Пребарај: #spainai

当前筛选 #spainai清除筛选
AI & Law

@ai_and_law · Post #164 · 14.11.2023 г., 08:04

Spain's AI Minister Calms Startups Amid AI Act Concerns Hello, everyone! Spain's AI and Digitalisation Minister, Carme Artigas, urges calm among AI startup founders regarding the AI Act. She assures that the Act's aim is to foster innovation, offering a two-year adaptation period and national sandbox initiatives to support companies. The legislation has undergone three years of extensive contemplation to ensure it remains adaptable amidst AI's rapid advancements. Despite challenges, Artigas is confident about reaching an agreement on the legislation by year-end. #SpainAI#AIAct#Innovation#AIPolicy

AI & Law

@ai_and_law · Post #104 · 05.09.2023 г., 07:04

New AI Regulatory Body Established in Spain Hello, everyone! Spain has taken a pioneering step in the European Union by creating a dedicated authority for the regulation of artificial intelligence. The Spanish Agency for the Supervision of Artificial Intelligence (AESIA) has been officially established through a Royal Decree and confirmed by the Council of Ministers on August 22. The institution aims to ensure that AI development in Spain aligns with inclusivity, sustainability, and the welfare of its citizens. It will oversee the National Artificial Intelligence Strategy, positioning Spain as a frontrunner in AI innovation. This move is part of Spain's Digital Spain 2025 Agenda, a €600 million initiative encompassing over 50 measures to shape the nation's digital future. AESIA is also expected to enforce the EU's landmark AI Act, putting Spain at the forefront of responsible AI regulation in Europe. #AIRegulation#SpainAI#DigitalEurope#Innovation#AESIA