[pypy-commit] pypy default: (ronan, mjacob) Make app-level time.sleep() release the GIL untranslated.

mjacob pypy.commits at gmail.com
Fri Feb 26 11:33:17 EST 2016


Author: Manuel Jacob <me at manueljacob.de>
Branch: 
Changeset: r82568:4f2954127738
Date: 2016-02-26 17:28 +0100
http://bitbucket.org/pypy/pypy/changeset/4f2954127738/

Log:	(ronan, mjacob) Make app-level time.sleep() release the GIL
	untranslated.

	Some app-level tests call time.sleep() to release the GIL. This
	didn't work reliably without hacks. This changeset also removes one
	of these hacks. The modified test wouldn't have passed without the
	interp_time.py change.

diff --git a/pypy/module/thread/test/test_thread.py b/pypy/module/thread/test/test_thread.py
--- a/pypy/module/thread/test/test_thread.py
+++ b/pypy/module/thread/test/test_thread.py
@@ -239,14 +239,12 @@
                 if waiting:
                     thread.interrupt_main()
                     return
-                print 'tock...', x  # <-force the GIL to be released, as
-                time.sleep(0.1)    #   time.sleep doesn't do non-translated
+                time.sleep(0.1)
 
         def busy_wait():
             waiting.append(None)
             for x in range(50):
-                print 'tick...', x  # <-force the GIL to be released, as
-                time.sleep(0.1)    #   time.sleep doesn't do non-translated
+                time.sleep(0.1)
             waiting.pop()
 
         # This is normally called by app_main.py
diff --git a/pypy/module/time/interp_time.py b/pypy/module/time/interp_time.py
--- a/pypy/module/time/interp_time.py
+++ b/pypy/module/time/interp_time.py
@@ -4,7 +4,7 @@
 from pypy.interpreter.gateway import unwrap_spec
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rlib.rarithmetic import intmask
-from rpython.rlib import rposix
+from rpython.rlib import rposix, rtime
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 import os
 import sys
@@ -316,13 +316,13 @@
         if secs < 0:
             raise OperationError(space.w_IOError,
                                  space.wrap("Invalid argument: negative time in sleep"))
-        pytime.sleep(secs)
+        rtime.sleep(secs)
 else:
     from rpython.rlib import rwin32
     from errno import EINTR
     def _simple_sleep(space, secs, interruptible):
         if secs == 0.0 or not interruptible:
-            pytime.sleep(secs)
+            rtime.sleep(secs)
         else:
             millisecs = int(secs * 1000)
             interrupt_event = space.fromcache(State).get_interrupt_event()
@@ -331,7 +331,7 @@
             if rc == rwin32.WAIT_OBJECT_0:
                 # Yield to make sure real Python signal handler
                 # called.
-                pytime.sleep(0.001)
+                rtime.sleep(0.001)
                 raise wrap_oserror(space,
                                    OSError(EINTR, "sleep() interrupted"))
     @unwrap_spec(secs=float)


More information about the pypy-commit mailing list