Отдельно разберём TaskGroup, который пришел на замену gather в Python 3.11.
Ключевые отличия
▫️create_task() возвращает объект asyncio.Task, у которого есть соответствюущие методы управления. То есть у нас больше контроля
▫️это контекстный менеджер, который гарантирует что все таски будут остановлены по выходу из контекста
▫️ошибка автоматически отменяет незавершенные задачи,
▫️except* передает нам ExceptionGroup, в котором каждую ошибку можно обработать отдельно
import asyncio
import random
async def do_it() -> str:
if random.random() < 0.1:
raise ValueError('Oops')
delay = random.uniform(0.5, 1.5)
await asyncio.sleep(delay)
return delay
async def main():
try:
async with asyncio.TaskGroup() as tg:
for _ in range(10):
tasks.append(tg.create_task(do_it()))
for t in tasks:
print(t.result())
except *ValueError as e:
for err in e.exceptions:
print(err)
asyncio.run(main())
Рекомендую изучить страницу Coroutines and Tasks из документации, где представлено больше интересных примеров и механизмов
- таймауты
- отмена задач
- создание задач из другого потока
#async
Совсем лайтовая статья для новичков "10 главных конструкций языка R".
Содержание:
- Комментарии
- Переменные и векторы
- Внешние модули
- Ввод и вывод
- Присваивание и сравнение
- Условный оператор if
- Цикл for
- Функции
- Классы, методы и объекты
#статьи
#easy
#Easy#Credit#T#i#ch#nh#s
Join the Easy Credit - Tài chính số beta on ✈️#TestFlight
🔗 Link: https://testflight.apple.com/join/B8XYxOWV
Shared by Dimitri
#python#deepseek#demo#easy#embedding#flask#gpt#huggingface_transformers#llm#mcp#multimodal#openai#qwen#rag#sentence_transformers#ui#vllm#vlm
UltraRAG is a lightweight framework that makes building retrieval-augmented generation (RAG) systems simple and fast. It uses a low-code approach where you write just dozens of lines of YAML configuration instead of complex code to create sophisticated AI workflows with conditional logic and loops. The framework includes a visual development environment where you can drag-and-drop to build pipelines, adjust parameters in real-time, and instantly convert your logic into interactive chat applications. This means you can deploy powerful AI systems that ground answers in your own data—reducing hallucinations and improving accuracy—without needing extensive coding expertise or lengthy development cycles.
https://github.com/OpenBMB/UltraRAG