Rather than streaming input in, opening and closing before each line to try and accommodate for race conditions, simply bite the bullet and preload files.
Load the entire file into a list, and close it. Parse it from memory and build the entire output into memory, and then write it.
Race conditions can be mentioned, like
if file hash changed:
print("Input file may have changed... Continue?")
Rather than streaming input in, opening and closing before each line to try and accommodate for race conditions, simply bite the bullet and preload files.
Load the entire file into a list, and close it. Parse it from memory and build the entire output into memory, and then write it.
Race conditions can be mentioned, like