From 060a800cc38ebb0d74c8822fdec421eac2dd402e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Boisselier?= Date: Fri, 24 Nov 2023 17:09:12 +0100 Subject: [PATCH] revert a4c2ead and add a PermissionError check instead --- K-ShakeTune/scripts/is_workflow.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/K-ShakeTune/scripts/is_workflow.py b/K-ShakeTune/scripts/is_workflow.py index 30ca525..74d89e0 100755 --- a/K-ShakeTune/scripts/is_workflow.py +++ b/K-ShakeTune/scripts/is_workflow.py @@ -49,15 +49,19 @@ RESULTS_SUBFOLDERS = ['belts', 'inputshaper', 'vibrations'] def is_file_open(filepath): - try: - with open(filepath, 'a') as file: - fcntl.flock(file.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) - # File is not in use (and can be used safely) - fcntl.flock(file.fileno(), fcntl.LOCK_UN) - return False - except IOError: - # File is still in use (and should not be touched for now) - return True + for proc in os.listdir('/proc'): + if proc.isdigit(): + for fd in glob.glob(f'/proc/{proc}/fd/*'): + try: + if os.path.samefile(fd, filepath): + return True + except FileNotFoundError: + # Klipper has already released the CSV file + pass + except PermissionError: + # Unable to check for this particular process due to permissions + pass + return False def get_belts_graph():