From e5e065b6699b33244e58b798e7b17b39bf2945a0 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Sun, 6 Jul 2003 18:36:54 +0000 Subject: [PATCH] New function sys.getcheckinterval(), to complement setcheckinterval(). --- Doc/lib/libsys.tex | 5 +++++ Lib/test/test_sys.py | 6 ++++-- Misc/NEWS | 3 +++ Python/sysmodule.c | 12 ++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Doc/lib/libsys.tex b/Doc/lib/libsys.tex index 558fb36e024..ea4aafaf8d2 100644 --- a/Doc/lib/libsys.tex +++ b/Doc/lib/libsys.tex @@ -197,6 +197,11 @@ It is always available. or when \code{os._exit()} is called.} \end{datadesc} +\begin{funcdesc}{getcheckinterval}{} + Return the interpreter's ``check interval''; + see \function{setcheckinterval()}. +\end{funcdesc} + \begin{funcdesc}{getdefaultencoding}{} Return the name of the current default string encoding used by the Unicode implementation. diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 0e61c6fce94..48336b45a72 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -172,8 +172,10 @@ class SysModuleTest(unittest.TestCase): def test_setcheckinterval(self): self.assertRaises(TypeError, sys.setcheckinterval) - sys.setcheckinterval(120) - sys.setcheckinterval(100) + orig = sys.getcheckinterval() + for n in 0, 100, 120, orig: # orig last to restore starting state + sys.setcheckinterval(n) + self.assertEquals(sys.getcheckinterval(), n) def test_recursionlimit(self): self.assertRaises(TypeError, sys.getrecursionlimit, 42) diff --git a/Misc/NEWS b/Misc/NEWS index 2953dc337dc..b793a73e3b7 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 2.3 release candidate? Core and builtins ----------------- +- The new function sys.getcheckinterval() returns the last value set + by sys.setcheckinterval(). + - The Windows implementation of PyThread_start_new_thread() never checked error returns from Windows functions correctly. As a result, it could claim to start a new thread even when the Microsoft diff --git a/Python/sysmodule.c b/Python/sysmodule.c index edbc2bf5805..8c77a88cbb7 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -431,6 +431,16 @@ Tell the Python interpreter to check for asynchronous events every\n\ n instructions. This also affects how often thread switches occur." ); +static PyObject * +sys_getcheckinterval(PyObject *self, PyObject *args) +{ + return PyInt_FromLong(_Py_CheckInterval); +} + +PyDoc_STRVAR(getcheckinterval_doc, +"getcheckinterval() -> current check interval; see setcheckinterval()." +); + static PyObject * sys_setrecursionlimit(PyObject *self, PyObject *args) { @@ -723,6 +733,8 @@ static PyMethodDef sys_methods[] = { #endif {"setcheckinterval", sys_setcheckinterval, METH_VARARGS, setcheckinterval_doc}, + {"getcheckinterval", sys_getcheckinterval, METH_NOARGS, + getcheckinterval_doc}, #ifdef HAVE_DLOPEN {"setdlopenflags", sys_setdlopenflags, METH_VARARGS, setdlopenflags_doc},