[pypy-commit] pypy py3.5: "Implement" sys.setswitchinterval(), by scaling the value and calling
arigo
pypy.commits at gmail.com
Tue Dec 6 10:07:41 EST 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r88908:edba47b26837
Date: 2016-12-06 16:06 +0100
http://bitbucket.org/pypy/pypy/changeset/edba47b26837/
Log: "Implement" sys.setswitchinterval(), by scaling the value and
calling sys.setcheckinterval().
diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py
--- a/pypy/module/sys/__init__.py
+++ b/pypy/module/sys/__init__.py
@@ -59,6 +59,8 @@
'getrecursionlimit' : 'vm.getrecursionlimit',
'setcheckinterval' : 'vm.setcheckinterval',
'getcheckinterval' : 'vm.getcheckinterval',
+ 'setswitchinterval' : 'vm.setswitchinterval',
+ 'getswitchinterval' : 'vm.getswitchinterval',
'exc_info' : 'vm.exc_info',
'settrace' : 'vm.settrace',
'gettrace' : 'vm.gettrace',
diff --git a/pypy/module/sys/test/test_sysmodule.py b/pypy/module/sys/test/test_sysmodule.py
--- a/pypy/module/sys/test/test_sysmodule.py
+++ b/pypy/module/sys/test/test_sysmodule.py
@@ -433,6 +433,14 @@
sys.setcheckinterval(n)
assert sys.getcheckinterval() == n
+ def test_setswitchinterval(self):
+ import sys
+ raises(TypeError, sys.setswitchinterval)
+ orig = sys.getswitchinterval()
+ for n in 1e-6, 0.1, orig: # orig last to restore starting state
+ sys.setswitchinterval(n)
+ assert sys.getswitchinterval() == n
+
def test_recursionlimit(self):
import sys
raises(TypeError, sys.getrecursionlimit, 42)
diff --git a/pypy/module/sys/vm.py b/pypy/module/sys/vm.py
--- a/pypy/module/sys/vm.py
+++ b/pypy/module/sys/vm.py
@@ -93,6 +93,22 @@
result = 0
return space.wrap(result)
+ at unwrap_spec(interval=float)
+def setswitchinterval(space, interval):
+ """For CPython compatibility, this maps to
+ sys.setcheckinterval(interval * 2000000)
+ """
+ # The scaling factor is chosen so that with the default
+ # checkinterval value of 10000, it corresponds to 0.005, which is
+ # the default value of the switchinterval in CPython 3.5
+ space.actionflag.setcheckinterval(int(interval * 2000000.0))
+
+def getswitchinterval(space):
+ """For CPython compatibility, this maps to
+ sys.getcheckinterval() / 2000000
+ """
+ return space.wrap(space.actionflag.getcheckinterval() / 2000000.0)
+
def exc_info(space):
"""Return the (type, value, traceback) of the most recent exception
caught by an except clause in the current stack frame or in an older stack
More information about the pypy-commit
mailing list