Функция asyncio.wait() это еще один способ вызвать множество асинхронных задач.
Она работает в нескольких режимах.
1. Самый простой - ждем завершения всех задач
async def main():
tasks = [asyncio.create_task(do_it(i)) for i in range(10)]
done, pending = await asyncio.wait(
tasks,
return_when=asyncio.ALL_COMPLETED
)
for task in done:
try:
print(task.result())
except Exception as e:
print(e)
Очень похоже на gather, но работает не так.
▫️возвращает не результаты, а два сета с объектами Task у которых можно забрать результат через task.result() если они в списке done
▫️не гарантирует порядок результатов так как оба объекта это set
▫️не выбрасывает исключение когда оно появляется, а сохраняет его в Task. Исключение появится когда попробуете забрать резултьтат.
2. Ждем завершения первой задачи, даже если там ошибка.
async def main():
tasks = [asyncio.create_task(do_it(i)) for i in range(3)]
done, pending = await asyncio.wait(
tasks,
return_when=asyncio.FIRST_COMPLETED
)
# в done может быть несколько задач!
for task in done:
try:
print(task.result())
except Exception as e:
print(f"Fail: {e}")
# Оставшиеся задачи в pending, как правило, нужно отменить, иначе они будут продолжать работать
for task in pending:
task.cancel()
В сете done будут таски которые успели завершится, причем как успешно так и нет.
3. До первой ошибки.
Тоже самое, но с аргументом FIRST_EXCEPTION
done, pending = await asyncio.wait(
tasks,
return_when=asyncio.FIRST_EXCEPTION
)
Функция завершается как только первая задача упадет с ошибкой.
Учтите, что в любом случае done вы можете обранужить несколько задач, как с ошибками так и успешные.
↗️ Полный листинг примеров здесь
#async
🇨🇳 La Chine a procédé au lancement réussi du satellite expérimental Shiyan‑33 qui sera principalement utilisé pour l’étude de l’environnement spatial, a rapporté l’agence Xinhua.
#chine#satellite#lancement
🌍 In 1972, the first Landsat satellite began photographing Earth's surface from space, fueling a new era of digital mapping and revealing real-time changes in forests, cities, and coastlines. ✨
#cartography⚡#satellite⚡#mapping⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 The deepest parts of the Amazon rainforest were first mapped by satellite only in the 21st century. Modern exploration now reveals hidden rivers and lost cities from space in this vast green wilderness. ✨
#exploration⚡#rainforest⚡#satellite⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 Space-based radar now tracks land subsiding from groundwater loss, revealing areas sinking by centimeters each year. These invisible changes help pinpoint regions at risk of flooding and damage. ✨
#remote⚡#sensing⚡#satellite⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
https://github.com/daleroberts/tv
tv ("#textview") is a small tool to quickly view high-resolution multi-band imagery directly in your terminal. It was designed for working with (very large) #satellite imagery data over a low-bandwidth connection. For example, you can directly visualise a Himawari 8 (11K x 11K pixel) image of the Earth directly from its URL:
It is built upon the wonderful #GDAL library so it is able to load a large variety of image formats (GeoTiff, PNG, Jpeg, NetCDF, ...) and subsample the image as it reads from disk so it can handle very large files quickly. It has the ability to read filenames (or URLs) from stdin and load files directly from URLs without writing locally to disk. Command line options are styled after gdal_translate such as:
-b to specify the bands (and ordering) to use,
-srcwin xoff yoff xsize ysize to view a subset of the image,
-r to specify the subsampling algorithm (nearest, bilinear, cubic, cubicspline, lanczos, average, mode).
$450K Fundraise for Bifrost Connect
OrbitalNerds has raised $450K for its innovative satellite SSH service, Bifrost Connect, on December 4, 2024. For more details, visit OrbitalNerds.
#Funding#Satellite#SSH#BifrostConnect#OrbitalNerds
Myriota Secures $50M Funding
Myriota has successfully raised $50 million in funding for its direct-to-orbit satellite connectivity solutions aimed at the Internet of Things. This funding round took place on December 19, 2024. For more details, visit Myriota.
#Myriota#Funding#Satellite#IoT#Connectivity#SpaceTech#DirectToOrbit#Investment#TechNews#Telecommunications