Author: Alex Gaynor <alex.gay...@gmail.com>
Branch: 
Changeset: r63752:580451252cc7
Date: 2013-04-29 07:51 -0700
http://bitbucket.org/pypy/pypy/changeset/580451252cc7/

Log:    merged upstream

diff --git a/lib-python/2.7/pydoc.py b/lib-python/2.7/pydoc.py
--- a/lib-python/2.7/pydoc.py
+++ b/lib-python/2.7/pydoc.py
@@ -1953,7 +1953,11 @@
                 if key is None:
                     callback(None, modname, '')
                 else:
-                    desc = split(__import__(modname).__doc__ or '', '\n')[0]
+                    try:
+                        module_doc = __import__(modname).__doc__
+                    except ImportError:
+                        module_doc = None
+                    desc = split(module_doc or '', '\n')[0]
                     if find(lower(modname + ' - ' + desc), key) >= 0:
                         callback(None, modname, desc)
 
diff --git a/py/_path/local.py b/py/_path/local.py
--- a/py/_path/local.py
+++ b/py/_path/local.py
@@ -655,7 +655,8 @@
     mkdtemp = classmethod(mkdtemp)
 
     def make_numbered_dir(cls, prefix='session-', rootdir=None, keep=3,
-                          lock_timeout = 172800):   # two days
+                          lock_timeout = 172800,   # two days
+                          min_timeout = 300):      # five minutes
         """ return unique directory with a number greater than the current
             maximum one.  The number is assumed to start directly after prefix.
             if keep is true directories with a number less than (maxnum-keep)
@@ -723,6 +724,20 @@
             for path in rootdir.listdir():
                 num = parse_num(path)
                 if num is not None and num <= (maxnum - keep):
+                    if min_timeout:
+                        # NB: doing this is needed to prevent (or reduce
+                        # a lot the chance of) the following situation:
+                        # 'keep+1' processes call make_numbered_dir() at
+                        # the same time, they create dirs, but then the
+                        # last process notices the first dir doesn't have
+                        # (yet) a .lock in it and kills it.
+                        try:
+                            t1 = path.lstat().mtime
+                            t2 = lockfile.lstat().mtime
+                            if abs(t2-t1) < min_timeout:
+                                continue   # skip directories too recent
+                        except py.error.Error:
+                            continue   # failure to get a time, better skip
                     lf = path.join('.lock')
                     try:
                         t1 = lf.lstat().mtime
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py 
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -2136,6 +2136,7 @@
 def test_errno_callback():
     if globals().get('PY_DOT_PY') == '2.5':
         py.test.skip("cannot run this test on py.py with Python 2.5")
+    set_errno(95)
     def cb():
         e = get_errno()
         set_errno(e - 6)
diff --git a/rpython/rtyper/test/test_runicode.py 
b/rpython/rtyper/test/test_runicode.py
--- a/rpython/rtyper/test/test_runicode.py
+++ b/rpython/rtyper/test/test_runicode.py
@@ -274,6 +274,7 @@
     test_char_isxxx = unsupported
     test_isdigit = unsupported
     test_str_isalpha = unsupported
+    test_str_isalnum = unsupported
     test_upper = unsupported
     test_lower = unsupported
     test_splitlines = unsupported
diff --git a/rpython/rtyper/tool/rffi_platform.py 
b/rpython/rtyper/tool/rffi_platform.py
--- a/rpython/rtyper/tool/rffi_platform.py
+++ b/rpython/rtyper/tool/rffi_platform.py
@@ -721,6 +721,8 @@
     eci = eci.convert_sources_to_files()
     files = [filepath]
     output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
+    if not output.startswith('-+- '):
+        raise Exception("run_example_code failed!\nlocals = %r" % (locals(),))
     section = None
     for line in output.splitlines():
         line = line.strip()
diff --git a/rpython/tool/gcc_cache.py b/rpython/tool/gcc_cache.py
--- a/rpython/tool/gcc_cache.py
+++ b/rpython/tool/gcc_cache.py
@@ -1,7 +1,7 @@
 from rpython.translator.platform import CompilationError
 from rpython.conftest import cache_dir
 from hashlib import md5
-import py
+import py, os
 
 cache_dir_root = py.path.local(cache_dir).ensure(dir=1)
 
@@ -35,37 +35,45 @@
             # compare equal to another instance without it
             if platform.log_errors != _previous:
                 platform.log_errors = _previous
-        path.write(result.out)
+        try_atomic_write(path, result.out)
         return result.out
 
+def try_atomic_write(path, data):
+    path = str(path)
+    tmppath = '%s~%d' % (path, os.getpid())
+    f = open(tmppath, 'wb')
+    f.write(data)
+    f.close()
+    try:
+        os.rename(tmppath, path)
+    except OSError:
+        try:
+            os.unlink(tmppath)
+        except OSError:
+            pass
+
 def try_compile_cache(c_files, eci):
-    "Try to compile a program; caches the result (starts with 'True' or 
'FAIL')"
+    "Try to compile a program.  If it works, caches this fact."
     # Import 'platform' every time, the compiler may have been changed
     from rpython.translator.platform import platform
     path = cache_file_path(c_files, eci, 'try_compile_cache')
     try:
         data = path.read()
+        if data == 'True':
+            return True
     except py.error.Error:
-        data = ''
-    if not (data.startswith('True') or data.startswith('FAIL\n')):
-        try:
-            _previous = platform.log_errors
-            try:
-                platform.log_errors = False
-                platform.compile(c_files, eci)
-            finally:
-                del platform.log_errors
-                # ^^^remove from the instance --- needed so that it can
-                # compare equal to another instance without it
-                if platform.log_errors != _previous:
-                    platform.log_errors = _previous
-            data = 'True'
-            path.write(data)
-        except CompilationError, e:
-            data = 'FAIL\n%s\n' % (e,)
-    if data.startswith('True'):
-        return True
-    else:
-        assert data.startswith('FAIL\n')
-        msg = data[len('FAIL\n'):]
-        raise CompilationError(msg.strip(), '')
+        pass
+    #
+    _previous = platform.log_errors
+    try:
+        platform.log_errors = False
+        platform.compile(c_files, eci)
+        # ^^^ may raise CompilationError.  We don't cache such results.
+    finally:
+        del platform.log_errors
+        # ^^^remove from the instance --- needed so that it can
+        # compare equal to another instance without it
+        if platform.log_errors != _previous:
+            platform.log_errors = _previous
+    path.write('True')
+    return True
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to