I am running a python script on a remote server through SSH. The script creates a new file, and writes some data to it. I do it in a while True
block. When I kill the python process, my output file is empty. How to save data to the output file?
When I use CTRL+C file keeps all data. But I can't use this combination, because I run script on remote machine, and I can lose the connection. Also, I am confused for how long this script will be running if I stop my SSH connection.
with open('out/' + filename, 'a') as f:
while True:
r = get_updates()
f.write(r.text)
time.sleep(10)