here is my question: I am writing a script to check if my site is working fine, the main idea is to get server response time and similar things every 5 minutes or so, and the script will log information every time after checking the server status. I know that you should not close the script while it is in the middle of checks / logs, but I'm curious if there are many servers to check, and also you have to do the input / output file quite often, which will happen if you close the script abruptly ?
OK, here is an example:
while True:
DemoFile = open("DemoFile.txt", "a")
DemoFile.write("This is a test!")
DemoFile.close()
time.sleep(30)
If I accidentally close the script while this line is DemoFile.write("This is a test!")running, what will I get in DemoFile.txt? Am I getting "This i" (an incomplete line) or a full line or a line not even added?
Hope someone knows the answer.
source
share