I have my python script with many print
statements in it.
It does some job that takes more than a day, so I need to track log in the output
file periodically while it is being executed.
if I execute
python migrate.py > output.txt
my file gets populated only after the script is finished (after 24 hours) which doesn't suite me. I tried as well with:
python migrate.py 2>&1 | tee output.txt
But in this case:
- nothing gets printed in the terminal while this is being executed
tail
command provides no output until script finishes...
I want to be able to see with tail
content of my output file but the size of the file is always 0
until the script is finished. Thanks a lot!
Edit: example of my code (if this is relevant, but I do not think so)
............
.............
.............
def main():
"""
Script main function
"""
start_time = datetime.datetime.now()
print ("----------------------------------------------------------------------------")
print ("### script started ###")
args = get_args()
print ("depot:"+depot)
print ("stream:"+args[0])
print ("destination:"+args[1])
print ("----------------------------------------------------------------------------")
logfile = get_history(args[0])
print ("----------------------------------------------------------------------------")
git_migrate(logfile, args[0], args[1], args[2], args[3], depot)
print ("----------------------------------------------------------------------------")
print ("### script completed ###")
end_time = datetime.datetime.now()
print('Duration: {}'.format(end_time - start_time))
if __name__ == '__main__':
main()