Skip to content

Commit 36456df

Browse files
authored
bpo-37392: Remove sys.setcheckinterval() (GH-14355)
Remove sys.getcheckinterval() and sys.setcheckinterval() functions. They were deprecated since Python 3.2. Use sys.getswitchinterval() and sys.setswitchinterval() instead. Remove also check_interval field of the PyInterpreterState structure.
1 parent 9fc720e commit 36456df

File tree

9 files changed

+14
-148
lines changed

9 files changed

+14
-148
lines changed

Doc/library/sys.rst

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -551,14 +551,6 @@ always available.
551551
.. versionadded:: 3.7
552552

553553

554-
.. function:: getcheckinterval()
555-
556-
Return the interpreter's "check interval"; see :func:`setcheckinterval`.
557-
558-
.. deprecated:: 3.2
559-
Use :func:`getswitchinterval` instead.
560-
561-
562554
.. function:: getdefaultencoding()
563555

564556
Return the name of the current default string encoding used by the Unicode
@@ -1141,21 +1133,6 @@ always available.
11411133
implement a dynamic prompt.
11421134

11431135

1144-
.. function:: setcheckinterval(interval)
1145-
1146-
Set the interpreter's "check interval". This integer value determines how often
1147-
the interpreter checks for periodic things such as thread switches and signal
1148-
handlers. The default is ``100``, meaning the check is performed every 100
1149-
Python virtual instructions. Setting it to a larger value may increase
1150-
performance for programs using threads. Setting it to a value ``<=`` 0 checks
1151-
every virtual instruction, maximizing responsiveness as well as overhead.
1152-
1153-
.. deprecated:: 3.2
1154-
This function doesn't have an effect anymore, as the internal logic for
1155-
thread switching and asynchronous tasks has been rewritten. Use
1156-
:func:`setswitchinterval` instead.
1157-
1158-
11591136
.. function:: setdlopenflags(n)
11601137

11611138
Set the flags used by the interpreter for :c:func:`dlopen` calls, such as when

Doc/whatsnew/3.9.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ Deprecated
122122
Removed
123123
=======
124124

125+
* The ``sys.getcheckinterval()`` and ``sys.setcheckinterval()`` functions have
126+
been removed. They were deprecated since Python 3.2. Use
127+
:func:`sys.getswitchinterval` and :func:`sys.setswitchinterval` instead.
128+
(Contributed by Victor Stinner in :issue:`37392`.)
129+
125130
* The C function ``PyImport_Cleanup()`` has been removed. It was documented as:
126131
"Empty the module table. For internal use only."
127132
(Contributed by Victor Stinner in :issue:`36710`.)

Include/internal/pycore_pystate.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ struct _is {
8282
PyObject *builtins;
8383
PyObject *importlib;
8484

85-
/* Used in Python/sysmodule.c. */
86-
int check_interval;
87-
8885
/* Used in Modules/_threadmodule.c. */
8986
long num_threads;
9087
/* Support for runtime thread stack size tuning.

Lib/test/test_sys.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,6 @@ def test_getdefaultencoding(self):
159159
# testing sys.settrace() is done in test_sys_settrace.py
160160
# testing sys.setprofile() is done in test_sys_setprofile.py
161161

162-
def test_setcheckinterval(self):
163-
with warnings.catch_warnings():
164-
warnings.simplefilter("ignore")
165-
self.assertRaises(TypeError, sys.setcheckinterval)
166-
orig = sys.getcheckinterval()
167-
for n in 0, 100, 120, orig: # orig last to restore starting state
168-
sys.setcheckinterval(n)
169-
self.assertEqual(sys.getcheckinterval(), n)
170-
171162
def test_switchinterval(self):
172163
self.assertRaises(TypeError, sys.setswitchinterval)
173164
self.assertRaises(TypeError, sys.setswitchinterval, "a")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Remove ``sys.getcheckinterval()`` and ``sys.setcheckinterval()`` functions.
2+
They were deprecated since Python 3.2. Use :func:`sys.getswitchinterval` and
3+
:func:`sys.setswitchinterval` instead. Remove also ``check_interval`` field of
4+
the ``PyInterpreterState`` structure.

Python/clinic/sysmodule.c.h

Lines changed: 1 addition & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/pystate.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ PyInterpreterState_New(void)
203203

204204
memset(interp, 0, sizeof(*interp));
205205
interp->id_refcount = -1;
206-
interp->check_interval = 100;
207206

208207
PyStatus status = PyConfig_InitPythonConfig(&interp->config);
209208
if (_PyStatus_EXCEPTION(status)) {

Python/sysmodule.c

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,56 +1025,6 @@ sys_getprofile_impl(PyObject *module)
10251025
return temp;
10261026
}
10271027

1028-
/*[clinic input]
1029-
sys.setcheckinterval
1030-
1031-
n: int
1032-
/
1033-
1034-
Set the async event check interval to n instructions.
1035-
1036-
This tells the Python interpreter to check for asynchronous events
1037-
every n instructions.
1038-
1039-
This also affects how often thread switches occur.
1040-
[clinic start generated code]*/
1041-
1042-
static PyObject *
1043-
sys_setcheckinterval_impl(PyObject *module, int n)
1044-
/*[clinic end generated code: output=3f686cef07e6e178 input=7a35b17bf22a6227]*/
1045-
{
1046-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
1047-
"sys.getcheckinterval() and sys.setcheckinterval() "
1048-
"are deprecated. Use sys.setswitchinterval() "
1049-
"instead.", 1) < 0) {
1050-
return NULL;
1051-
}
1052-
1053-
PyThreadState *tstate = _PyThreadState_GET();
1054-
tstate->interp->check_interval = n;
1055-
Py_RETURN_NONE;
1056-
}
1057-
1058-
/*[clinic input]
1059-
sys.getcheckinterval
1060-
1061-
Return the current check interval; see sys.setcheckinterval().
1062-
[clinic start generated code]*/
1063-
1064-
static PyObject *
1065-
sys_getcheckinterval_impl(PyObject *module)
1066-
/*[clinic end generated code: output=1b5060bf2b23a47c input=4b6589cbcca1db4e]*/
1067-
{
1068-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
1069-
"sys.getcheckinterval() and sys.setcheckinterval() "
1070-
"are deprecated. Use sys.getswitchinterval() "
1071-
"instead.", 1) < 0) {
1072-
return NULL;
1073-
}
1074-
1075-
PyThreadState *tstate = _PyThreadState_GET();
1076-
return PyLong_FromLong(tstate->interp->check_interval);
1077-
}
10781028

10791029
/*[clinic input]
10801030
sys.setswitchinterval
@@ -1990,8 +1940,6 @@ static PyMethodDef sys_methods[] = {
19901940
SYS_INTERN_METHODDEF
19911941
SYS_IS_FINALIZING_METHODDEF
19921942
SYS_MDEBUG_METHODDEF
1993-
SYS_SETCHECKINTERVAL_METHODDEF
1994-
SYS_GETCHECKINTERVAL_METHODDEF
19951943
SYS_SETSWITCHINTERVAL_METHODDEF
19961944
SYS_GETSWITCHINTERVAL_METHODDEF
19971945
SYS_SETDLOPENFLAGS_METHODDEF
@@ -2430,7 +2378,6 @@ getrefcount() -- return the reference count for an object (plus one :-)\n\
24302378
getrecursionlimit() -- return the max recursion depth for the interpreter\n\
24312379
getsizeof() -- return the size of an object in bytes\n\
24322380
gettrace() -- get the global debug tracing function\n\
2433-
setcheckinterval() -- control how often the interpreter checks for events\n\
24342381
setdlopenflags() -- set the flags to be used for dlopen() calls\n\
24352382
setprofile() -- set the global profiling function\n\
24362383
setrecursionlimit() -- set the max recursion depth for the interpreter\n\

Tools/ccbench/ccbench.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,12 @@ def main():
541541
help="run I/O bandwidth tests")
542542
parser.add_option("-i", "--interval",
543543
action="store", type="int", dest="check_interval", default=None,
544-
help="sys.setcheckinterval() value")
544+
help="sys.setcheckinterval() value "
545+
"(Python 3.8 and older)")
545546
parser.add_option("-I", "--switch-interval",
546547
action="store", type="float", dest="switch_interval", default=None,
547-
help="sys.setswitchinterval() value")
548+
help="sys.setswitchinterval() value "
549+
"(Python 3.2 and newer)")
548550
parser.add_option("-n", "--num-threads",
549551
action="store", type="int", dest="nthreads", default=4,
550552
help="max number of threads in tests")

0 commit comments

Comments
 (0)