with touchopen('./tool.run', 'r+') as doing_fd:
    fcntl.lockf(doing_fd, fcntl.LOCK_EX)
previous_value = doing_fd.read()
print(previous_value)
doing_fd.seek(0)
doing_fd.write('new value')
doing_fd.truncate()
How to open (read-write) or create a file with truncation possible?