Script execution

This commit is contained in:
gac-x04sa
2019-02-26 15:32:30 +01:00
parent a4d198c50e
commit b73b7b5e50
+14 -7
View File
@@ -81,35 +81,42 @@ def is_locked(filepath):
print "%s not found." % filepath
return locked
def wait_for_files(filepaths):
def wait_for_files(filepaths, timeout = None):
"""Checks if the files are ready.
For a file to be ready it must exist and can be opened in append
mode.
"""
wait_time = 5
wait_time = 0.01
for filepath in filepaths:
filepath = os.path.abspath(filepath)
# If the file doesn't exist, wait wait_time seconds and try again
# until it's found.
while not os.path.exists(filepath):
print "%s hasn't arrived. Waiting %s seconds." % \
(filepath, wait_time)
if (timeout is not None) and (time.time() -start > timeout):
raise Exception(filepath + " hasn't arrived in time")
time.sleep(wait_time)
# If the file exists but locked, wait wait_time seconds and check
# again until it's no longer locked by another process.
while is_locked(filepath):
print "%s is currently in use. Waiting %s seconds." % \
(filepath, wait_time)
if (timeout is not None) and (time.time() -start > timeout):
raise Exception(filepath + " hasn't arrived in time")
time.sleep(wait_time)
def wait_for_file_size(filepath, size):
def wait_for_file_size(filepath, size, timeout = None):
"""Wait for a file to exist, and reach a given size.
"""
wait_time = 0.01
filepath = os.path.abspath(filepath)
start = time.time()
# If the file doesn't exist, wait wait_time seconds and try again
# until it's found.
while not os.path.exists(filepath) or size > os.path.getsize(filepath):
if (timeout is not None) and (time.time() -start > timeout):
raise Exception(filepath + " hasn't arrived in time")
time.sleep(wait_time)