]> granicus.if.org Git - python/commitdiff
Issue #26939: Add the support.setswitchinterval() function to fix
authorXavier de Gaye <xdegaye@users.sourceforge.net>
Thu, 8 Dec 2016 10:06:56 +0000 (11:06 +0100)
committerXavier de Gaye <xdegaye@users.sourceforge.net>
Thu, 8 Dec 2016 10:06:56 +0000 (11:06 +0100)
test_functools hanging on the Android armv7 qemu emulator.

Lib/test/support/__init__.py
Lib/test/test_functools.py
Misc/NEWS

index 1e2777751745690d75147838d2e770ad95b31dee..fa344ece2386f2fcd1fd0ab9578252bfbcde4ad3 100644 (file)
@@ -93,6 +93,7 @@ __all__ = [
     "check__all__", "requires_android_level", "requires_multiprocessing_queue",
     # sys
     "is_jython", "is_android", "check_impl_detail", "unix_shell",
+    "setswitchinterval",
     # network
     "HOST", "IPV6_ENABLED", "find_unused_port", "bind_port", "open_urlresource",
     # processes
@@ -2547,3 +2548,18 @@ def missing_compiler_executable(cmd_names=[]):
             continue
         if spawn.find_executable(cmd[0]) is None:
             return cmd[0]
+
+
+_is_android_emulator = None
+def setswitchinterval(interval):
+    # Setting a very low gil interval on the Android emulator causes python
+    # to hang (issue #26939).
+    minimum_interval = 1e-5
+    if is_android and interval < minimum_interval:
+        global _is_android_emulator
+        if _is_android_emulator is None:
+            _is_android_emulator = (subprocess.check_output(
+                               ['getprop', 'ro.kernel.qemu']).strip() == b'1')
+        if _is_android_emulator:
+            interval = minimum_interval
+    return sys.setswitchinterval(interval)
index 75427dfad3420caf6bfc79cc53c0ab4495fbe6c2..ba2a52fb7341fed14f5423804f33d4e0f1badd3f 100644 (file)
@@ -1322,7 +1322,7 @@ class TestLRU:
                 f.cache_clear()
 
         orig_si = sys.getswitchinterval()
-        sys.setswitchinterval(1e-6)
+        support.setswitchinterval(1e-6)
         try:
             # create n threads in order to fill cache
             threads = [threading.Thread(target=full, args=[k])
index 8023df36a0b5dcbd66679738609ceb68b8823b96..a15bb9bf871f1985ea0d0a1287e5bc9149bd24b0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -22,6 +22,12 @@ Library
 - Issue #28847: dbm.dumb now supports reading read-only files and no longer
   writes the index file when it is not changed.
 
+Tests
+-----
+
+- Issue #26939: Add the support.setswitchinterval() function to fix
+  test_functools hanging on the Android armv7 qemu emulator.
+
 
 What's New in Python 3.6.0 release candidate 1
 ==============================================