Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions pkgs/development/interpreters/python/cpython/2.7/atomic_pyc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
diff --git a/Lib/py_compile.py b/Lib/py_compile.py
index 978da73..3559eb9 100644
--- a/Lib/py_compile.py
+++ b/Lib/py_compile.py
@@ -120,16 +120,27 @@ def compile(file, cfile=None, dfile=None, doraise=False):
return
if cfile is None:
cfile = file + (__debug__ and 'c' or 'o')
- with open(cfile, 'wb') as fc:
- fc.write('\0\0\0\0')
- if "DETERMINISTIC_BUILD" in os.environ:
+ # Atomically write the pyc/pyo file. Issue #13146.
+ # id() is used to generate a pseudo-random filename.
+ path_tmp = '{}.{}'.format(cfile, id(cfile))
+ try:
+ with open(path_tmp, 'wb') as fc:
fc.write('\0\0\0\0')
- else:
- wr_long(fc, timestamp)
- marshal.dump(codeobject, fc)
- fc.flush()
- fc.seek(0, 0)
- fc.write(MAGIC)
+ if "DETERMINISTIC_BUILD" in os.environ:
+ fc.write('\0\0\0\0')
+ else:
+ wr_long(fc, timestamp)
+ marshal.dump(codeobject, fc)
+ fc.flush()
+ fc.seek(0, 0)
+ fc.write(MAGIC)
+ os.rename(path_tmp, cfile)
+ except OSError:
+ try:
+ os.unlink(path_tmp)
+ except OSError:
+ pass
+ raise

def main(args=None):
"""Compile several source files.
6 changes: 6 additions & 0 deletions pkgs/development/interpreters/python/cpython/2.7/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ let
sha256 = "0l9rw6r5r90iybdkp3hhl2pf0h0s1izc68h5d3ywrm92pq32wz57";
})

# Fix race-condition during pyc creation. Has a slight backwards
# incompatible effect: pyc symlinks will now be overridden
# (https://bugs.python.org/issue17222). Included in python >= 3.4,
# backported in debian since 2013.
# https://bugs.python.org/issue13146
./atomic_pyc.patch
] ++ optionals (x11Support && stdenv.isDarwin) [
./use-correct-tcl-tk-on-darwin.patch
] ++ optionals stdenv.isLinux [
Expand Down