Race condition in DiskStore by adrianomarto · Pull Request #470 · webpy/webpy

@gmelikov, if you look at the code carefully, you will see that the file is closed in the "finally" clause (and it was already like this before my changes). That should suffice to take care of the crash condition, which is not the problem being addressed here.

The problem I am trying to solve happens when a thread tries to read the file when the file is still being written. The problem still happens if you move the file from elsewhere instead of writing the file directly to where it belongs.

Solving the problem by moving the file form a temporary folder would require the moving operation to be atomic, which I don't dare say to the case in all operating systems. On the other hand, solving the problem by using locks is guaranteed to work, as the locking operation is atomic regardless of the operating system.