1 new changeset in pytest:

http://bitbucket.org/hpk42/pytest/changeset/944895de1103/
changeset:   944895de1103
user:        gutworth
date:        2011-07-05 19:02:53
summary:     insure moving pyc files around is atomic
affected #:  1 file (200 bytes)

--- a/_pytest/assertion/rewrite.py      Tue Jul 05 18:01:31 2011 +0200
+++ b/_pytest/assertion/rewrite.py      Tue Jul 05 12:02:53 2011 -0500
@@ -87,7 +87,7 @@
         cache = py.path.local(fn_pypath.dirname).join("__pycache__", cache_fn)
         if _use_cached_pyc(fn_pypath, cache):
             state.trace("found cached rewritten pyc for %r" % (fn,))
-            cache.copy(pyc)
+            _atomic_copy(cache, pyc)
         else:
             state.trace("rewriting %r" % (fn,))
             _make_rewritten_pyc(state, fn_pypath, pyc)
@@ -163,10 +163,16 @@
 def _cache_pyc(state, pyc, cache):
     try:
         cache.dirpath().ensure(dir=True)
-        pyc.copy(cache)
+        _atomic_copy(pyc, cache)
     except EnvironmentError:
         state.trace("failed to cache %r as %r" % (pyc, cache))
 
+def _atomic_copy(orig, to):
+    """An atomic copy (at least on POSIX platforms)"""
+    temp = py.path.local(orig.strpath + str(os.getpid()))
+    orig.copy(temp)
+    temp.rename(to)
+
 
 def rewrite_asserts(mod):
     """Rewrite the assert statements in mod."""

Repository URL: https://bitbucket.org/hpk42/pytest/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
_______________________________________________
py-svn mailing list
py-svn@codespeak.net
http://codespeak.net/mailman/listinfo/py-svn

Reply via email to