Skip to content

Instantly share code, notes, and snippets.

@klprint
Created September 30, 2016 08:59
Show Gist options
  • Save klprint/aa7e5bbb35f1240797fab9ea03f793fd to your computer and use it in GitHub Desktop.
Save klprint/aa7e5bbb35f1240797fab9ea03f793fd to your computer and use it in GitHub Desktop.
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