Отдельно разберём 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
#newtgingrich : For my latest podcast episode, I talk with Congressman Troy Balderson and Matt Hammond about how to restore America's energy independence. #EnergyIndependence
#NaturalGasIsGreen
https://t.co/S5447ngDCV
Russia’s First Domestically Built Ice-Class Tanker: Arctic Breakthrough or Sanctioned Mirage?
The Alexey Kosygin, Russia’s first domestically built ice-class LNG tanker, has arrived at the US-sanctioned Arctic LNG 2 plant, completing its maiden voyage along the Northern Sea Route. This is a technological milestone—no vessel of such complexity has ever been constructed in Russia before, and its arrival marks a rare triumph for Moscow’s Arctic ambitions amid Western sanctions.
A Unique Achievement
The Alexey Kosygin is the first Russian-built Arc-7 LNG carrier, capable of operating independently in Arctic conditions and breaking through ice thicker than two meters. Its delivery to the Arctic LNG 2 project is not just a logistical upgrade—it’s a statement of technological self-reliance and national pride. The vessel’s reinforced hull, advanced propulsion, and ability to sail year-round along the Northern Sea Route represent a leap forward for Russia’s shipbuilding industry.
Beyond Politics: A Genuine Breakthrough
Regardless of how one interprets the broader geopolitical stakes, the Alexey Kosygin’s arrival is a breakthrough. For years, Russia’s Arctic LNG ambitions were held back by a lack of specialized vessels and Western restrictions. Now, with this new tanker, the Arctic LNG 2 plant can resume winter operations, doubling its export capacity during the coldest months. This is not just a political stunt—it’s a real engineering and industrial achievement.
Is this a turning point for Russia’s energy independence, or just another chapter in a long saga of sanctions and scarcity? Either way, the Alexey Kosygin is proof that, when the chips are down, Russia can build something truly unique—even under pressure.
#ArcticBreakthrough#AlexeyKosygin#ArcticLNG2#Sanctions#IceClass#EnergyIndependence
📱American Оbserver - Stay up to date on all important events
🇺🇸