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):
for proc in os.listdir('/proc'):
if proc.isdigit():
for fd in glob.glob(f'/proc/{proc}/fd/*'):
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)
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():