[pypy-svn] r17117 - in pypy/dist/pypy: interpreter module/sys module/thread/test

arigo at codespeak.net arigo at codespeak.net
Wed Aug 31 15:06:40 CEST 2005


Author: arigo
Date: Wed Aug 31 15:06:36 2005
New Revision: 17117

Modified:
   pypy/dist/pypy/interpreter/executioncontext.py
   pypy/dist/pypy/module/sys/vm.py
   pypy/dist/pypy/module/thread/test/support.py
Log:
threads: use the value specified in sys.setcheckinterval() as intended, to
only release the GIL every nth bytecode.

For now, the thread tests must force a sys.setcheckinterval(1).  This is not
particularly elegant and quite fragile until, and if, we have a way to release
the GIL around system calls in py.py.



Modified: pypy/dist/pypy/interpreter/executioncontext.py
==============================================================================
--- pypy/dist/pypy/interpreter/executioncontext.py	(original)
+++ pypy/dist/pypy/interpreter/executioncontext.py	Wed Aug 31 15:06:36 2005
@@ -12,6 +12,7 @@
         self.w_tracefunc = None
         self.w_profilefunc = None
         self.is_tracing = 0
+        self.ticker = 0
         self.compiler = space.createcompiler()
 
     def enter(self, frame):
@@ -58,10 +59,13 @@
     def bytecode_trace(self, frame):
         "Trace function called before each bytecode."
 
-        # First, call yield_thread() before each bytecode ---
-        # XXX this should be called only every N bytecodes,
+        # First, call yield_thread() before each Nth bytecode,
         #     as selected by sys.setcheckinterval()
-        self.space.threadlocals.yield_thread()
+        ticker = self.ticker
+        if ticker <= 0:
+            self.space.threadlocals.yield_thread()
+            ticker = self.space.sys.checkinterval
+        self.ticker = ticker - 1
 
         # Tracing logic
         if self.is_tracing or frame.w_f_trace is None:

Modified: pypy/dist/pypy/module/sys/vm.py
==============================================================================
--- pypy/dist/pypy/module/sys/vm.py	(original)
+++ pypy/dist/pypy/module/sys/vm.py	Wed Aug 31 15:06:36 2005
@@ -53,13 +53,12 @@
 
     return space.wrap(space.sys.recursionlimit)
 
-checkinterval = 100
-
 def setcheckinterval(space, w_interval):
     """setcheckinterval(n)
     Tell the Python interpreter to check for asynchronous events every
     n instructions.  This also affects how often thread switches occur."""
     space.sys.checkinterval = space.int_w(w_interval) 
+    space.getexecutioncontext().ticker = 0
 
 def getcheckinterval(space):
     """getcheckinterval() -> current check interval; see setcheckinterval()."""

Modified: pypy/dist/pypy/module/thread/test/support.py
==============================================================================
--- pypy/dist/pypy/module/thread/test/support.py	(original)
+++ pypy/dist/pypy/module/thread/test/support.py	Wed Aug 31 15:06:36 2005
@@ -26,3 +26,8 @@
                     time.sleep(0.002)
             return busywait
         """)
+
+        space.appexec([], """():
+            import sys
+            sys.setcheckinterval(1)
+        """)



More information about the Pypy-commit mailing list