revert a4c2ead and add a PermissionError check instead

This commit is contained in:
Félix Boisselier
2023-11-24 17:09:12 +01:00
parent 7c76be5077
commit 060a800cc3

View File

@@ -49,15 +49,19 @@ RESULTS_SUBFOLDERS = ['belts', 'inputshaper', 'vibrations']
def is_file_open(filepath): def is_file_open(filepath):
try: for proc in os.listdir('/proc'):
with open(filepath, 'a') as file: if proc.isdigit():
fcntl.flock(file.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) for fd in glob.glob(f'/proc/{proc}/fd/*'):
# File is not in use (and can be used safely) try:
fcntl.flock(file.fileno(), fcntl.LOCK_UN) if os.path.samefile(fd, filepath):
return False return True
except IOError: except FileNotFoundError:
# File is still in use (and should not be touched for now) # Klipper has already released the CSV file
return True pass
except PermissionError:
# Unable to check for this particular process due to permissions
pass
return False
def get_belts_graph(): def get_belts_graph():