diff options
author | Jason Gunthorpe <jgg@mellanox.com> | 2020-02-07 11:52:43 -0400 |
---|---|---|
committer | Jason Gunthorpe <jgg@mellanox.com> | 2020-02-07 12:11:03 -0400 |
commit | d1877aaf5a791204dd7222f50fc33b5f802c7e94 (patch) | |
tree | 8c6db52a7656bc99da9e196913de95953771fbc5 /cloud_mdir_sync/main.py | |
parent | f44a42f276e01514a1e4bf3028639aaea58138c6 (diff) | |
download | cloud_mdir_sync-d1877aaf5a791204dd7222f50fc33b5f802c7e94.tar.gz cloud_mdir_sync-d1877aaf5a791204dd7222f50fc33b5f802c7e94.tar.bz2 cloud_mdir_sync-d1877aaf5a791204dd7222f50fc33b5f802c7e94.zip |
Don't leave asyncio tasks running unexpectedly
All cases where gather is called intend that the tasks will complete
successfully or all cancel at the first error. Add a little wrapper to
achieve this.
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Diffstat (limited to 'cloud_mdir_sync/main.py')
-rw-r--r-- | cloud_mdir_sync/main.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/cloud_mdir_sync/main.py b/cloud_mdir_sync/main.py index af179cb..d810956 100644 --- a/cloud_mdir_sync/main.py +++ b/cloud_mdir_sync/main.py @@ -9,6 +9,7 @@ import aiohttp import pyinotify from . import config, mailbox, messages, oauth +from .util import asyncio_complete def route_cloud_messages(cfg: config.Config) -> messages.MBoxDict_Type: @@ -48,7 +49,7 @@ async def update_cloud_from_local(cfg: config.Config, if lmsg is None and offline_mode: continue msgs_by_cloud[cloud_msg.mailbox][ch] = (lmsg, cloud_msg) - await asyncio.gather(*( + await asyncio_complete(*( mbox.merge_content(msgdict) for mbox, msgdict in msgs_by_cloud.items() if not mbox.same_messages(msgdict, tuple_form=True))) @@ -59,15 +60,15 @@ async def synchronize_mail(cfg: config.Config): try: await cfg.web_app.go() - await asyncio.gather(*(mbox.setup_mbox() - for mbox in cfg.all_mboxes())) + await asyncio_complete(*(mbox.setup_mbox() + for mbox in cfg.all_mboxes())) msgs = None while True: try: - await asyncio.gather(*(mbox.update_message_list() - for mbox in cfg.all_mboxes() - if mbox.need_update)) + await asyncio_complete(*(mbox.update_message_list() + for mbox in cfg.all_mboxes() + if mbox.need_update)) nmsgs = route_cloud_messages(cfg) if msgs is not None: @@ -92,8 +93,8 @@ async def synchronize_mail(cfg: config.Config): cfg.msgdb.cleanup_msgs(msgs) cfg.logger.debug("Changed event, looping") finally: - await asyncio.gather(*(domain.close() - for domain in cfg.domains.values())) + await asyncio_complete(*(domain.close() + for domain in cfg.domains.values())) cfg.domains = {} await cfg.web_app.close() |