Skip to content

Commit

Permalink
Handle exceptions gracefully in disk usage retrieval
Browse files Browse the repository at this point in the history
Updated the refresh_info method to handle exceptions that may occur during disk usage retrieval using psutil.disk_usage(). Added try-except block to catch any exceptions, such as permission errors, and continue processing other partitions if an exception occurs. Error messages are printed for each partition where an exception occurs to aid in debugging.
  • Loading branch information
healthonrails committed Apr 18, 2024
1 parent 4132794 commit 07ce1a1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions annolid/gui/widgets/about_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ def refresh_info(self):
partitions = psutil.disk_partitions()
disk_info = ""
for partition in partitions:
usage = psutil.disk_usage(partition.mountpoint)
disk_info += f"{partition.device} - Total: {usage.total / (1024 ** 3):.2f} GB"
disk_info += f"Used: {usage.used / (1024 ** 3):.2f} GB\n"
try:
usage = psutil.disk_usage(partition.mountpoint)
disk_info += f"{partition.device} - Total: {usage.total / (1024 ** 3):.2f} GB"
disk_info += f"Used: {usage.used / (1024 ** 3):.2f} GB\n"
except Exception as e:
print(
f"Error retrieving disk usage for {partition.mountpoint}: {e}")
self.disk_label.setText(disk_info)


Expand Down

0 comments on commit 07ce1a1

Please sign in to comment.