From 8b915b149674a0d77b51a6f7ebba0602731cf2da Mon Sep 17 00:00:00 2001 From: William Moore Date: Thu, 28 Sep 2023 21:44:22 +0100 Subject: [PATCH] Add try/except around submit() to handle failures --- src/omero_demo_cleanup/library.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/omero_demo_cleanup/library.py b/src/omero_demo_cleanup/library.py index 996a854..d2044e6 100755 --- a/src/omero_demo_cleanup/library.py +++ b/src/omero_demo_cleanup/library.py @@ -319,21 +319,24 @@ def resource_usage( for user_id, user_name in users.items(): print(f'Finding disk usage of "{user_name}" (#{user_id}).') user = {"Experimenter": [user_id]} - rsp = submit(conn, DiskUsage2(targetObjects=user), DiskUsage2Response) - file_count = 0 file_size = 0 - for who, usage in rsp.totalFileCount.items(): - if who.first == user_id: - file_count += usage - for who, usage in rsp.totalBytesUsed.items(): - if who.first == user_id: - file_size += usage + try: + rsp = submit(conn, DiskUsage2(targetObjects=user), DiskUsage2Response) + + for who, usage in rsp.totalFileCount.items(): + if who.first == user_id: + file_count += usage + for who, usage in rsp.totalBytesUsed.items(): + if who.first == user_id: + file_size += usage + except Exception: + print(f'FAILED to count data for "{user_name}" (#{user_id}).') if file_count > 0 or file_size > 0: user_stats.append( - UserStats(user_id, user_name, file_count, file_size, logouts[user_id]) + UserStats(user_id, user_name, file_count, file_size, logouts.get(user_id, 0)) ) return user_stats