Отдельно разберём 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
#javascript#hacktoberfest#stremio
Stremio is an easy-to-use media center app that lets you find, watch, and organize movies, TV shows, live channels, and more from many sources in one place. You can install addons to add content, sync your library across devices, and even download videos for offline viewing. It supports subtitles, Chromecast streaming, and high-quality formats like 4K HDR. Stremio keeps your data safe by running addons remotely and respects your privacy with minimal data collection. This means you get a secure, convenient, and personalized streaming experience without switching apps or worrying about security.
https://github.com/Stremio/stremio-web
Stremio
Freedom To Watch Everything You Want
Stremio is a modern media center that's a one-stop solution for your video entertainment. You discover, watch and organize video content from easy to install addons. Movies, TV shows, live TV or web channels - find all this on Stremio.
Features:
• Multi-platform support
• Discover new content with ease
• Extendable video catalogue
• All of your video content on one screen
• Organize your video library
• Keep track of everything you watch
• Cast to another device
• Watch video from many different sources
• Play HTTP links and torrent files
Download: https://www.stremio.com/downloads
https://github.com/Stremio
⚠️ Not fully foss?
#Stremio#movies
@foss_desktop