using fcntl to check if a file is still open by klipper
This commit is contained in:
@@ -32,6 +32,7 @@ import glob
|
|||||||
import sys
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
import tarfile
|
import tarfile
|
||||||
|
import fcntl
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
#################################################################################################################
|
#################################################################################################################
|
||||||
@@ -48,15 +49,15 @@ RESULTS_SUBFOLDERS = ['belts', 'inputshaper', 'vibrations']
|
|||||||
|
|
||||||
|
|
||||||
def is_file_open(filepath):
|
def is_file_open(filepath):
|
||||||
for proc in os.listdir('/proc'):
|
try:
|
||||||
if proc.isdigit():
|
with open(filepath, 'a') as file:
|
||||||
for fd in glob.glob(f'/proc/{proc}/fd/*'):
|
fcntl.flock(file.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
try:
|
# File is not in use (and can be used safely)
|
||||||
if os.path.samefile(fd, filepath):
|
fcntl.flock(file.fileno(), fcntl.LOCK_UN)
|
||||||
return True
|
return False
|
||||||
except FileNotFoundError:
|
except IOError:
|
||||||
pass
|
# File is still in use (and should not be touched for now)
|
||||||
return False
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_belts_graph():
|
def get_belts_graph():
|
||||||
|
|||||||
Reference in New Issue
Block a user