on windows, rename is not atomic, so utilize exclusive access to the file
This commit is contained in:
parent
8c683acad1
commit
639f35bbc4
|
@ -153,11 +153,16 @@ def _make_rewritten_pyc(state, fn, pyc):
|
||||||
# assertion rewriting, but I don't know of a fast way to tell.
|
# assertion rewriting, but I don't know of a fast way to tell.
|
||||||
state.trace("failed to compile: %r" % (fn,))
|
state.trace("failed to compile: %r" % (fn,))
|
||||||
return None
|
return None
|
||||||
# Dump the code object into a file specific to this process.
|
if sys.platform.startswith("win"):
|
||||||
proc_pyc = pyc + "." + str(os.getpid())
|
# Windows grants exclusive access to open files and doesn't have atomic
|
||||||
_write_pyc(co, fn, proc_pyc)
|
# rename, so just write into the final file.
|
||||||
# Atomically replace the pyc.
|
_write_pyc(co, fn, pyc)
|
||||||
os.rename(proc_pyc, pyc)
|
else:
|
||||||
|
# When not on windows, assume rename is atomic. Dump the code object
|
||||||
|
# into a file specific to this process and atomically replace it.
|
||||||
|
proc_pyc = pyc + "." + str(os.getpid())
|
||||||
|
_write_pyc(co, fn, proc_pyc)
|
||||||
|
os.rename(proc_pyc, pyc)
|
||||||
return co
|
return co
|
||||||
|
|
||||||
def _read_pyc(source, pyc):
|
def _read_pyc(source, pyc):
|
||||||
|
|
Loading…
Reference in New Issue