Created
September 30, 2016 08:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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