Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This python function checks whether a file exists. If not, the function waits for a user specified time and checks again. As soon as the file appears, a reaction can be specified. A log is written while the function runs to inform the user about the current status.
def check_output(file, interval_time, logfile_path):
import os
import time
status = os.path.isfile(file)
while status is not True:
f_log = open(logfile_path, 'a')
f_log.write(time.asctime() + '\t' + 'Still running\n')
f_log.close()
time.sleep(interval_time)
status = os.path.isfile(file)
# What should be done after the file appears?
# This goes here:
f_log = open(logfile_path, 'a')
f_log.write(time.asctime() + '\t' + 'FINISHED\n')
f_log.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment