diff -r 849826a900d2 Lib/test/support/__init__.py --- a/Lib/test/support/__init__.py Tue Oct 25 21:49:19 2016 -0500 +++ b/Lib/test/support/__init__.py Fri Oct 28 09:11:27 2016 +0200 @@ -93,6 +93,7 @@ "check__all__", # sys "is_jython", "is_android", "check_impl_detail", "unix_shell", + "setswitchinterval", # network "HOST", "IPV6_ENABLED", "find_unused_port", "bind_port", "open_urlresource", # processes @@ -2467,3 +2468,18 @@ # The sequence should be deallocated just after the end of iterating gc_collect() test.assertTrue(done) + + +_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) diff -r 849826a900d2 Lib/test/test_functools.py --- a/Lib/test/test_functools.py Tue Oct 25 21:49:19 2016 -0500 +++ b/Lib/test/test_functools.py Fri Oct 28 09:11:27 2016 +0200 @@ -1303,7 +1303,7 @@ 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])