Closed jwilk closed 7 years ago
Computers are horrible. I guess the solution is to write it to tempfile.mkstemp()
and then os.rename
it?
Computers were invented solely to make programmers' lives miserable. ;-)
Yup, os.rename()
should do the trick on UNIX; I'd use tempfile.NamedTemporaryFile(delete=False)
instead of mkstemp()
.
But on Windows, os.rename()
fails when the destination file exists. Hmm, I guess in RPLY's case, you could just ignore exceptions from os.rename()
.
RPLY doesn't create cache files atomically. Therefore it's possible that one ParserGenerator reads the cache file when it's already created, but not yet fully written by another ParserGenerator. Here's a simple reproducer, which tries to create two grammars in parallel:
Sooner or later it fails with: