cpython: 2b21fcf3d9a9 (original) (raw)

Mercurial > cpython

changeset 69710:2b21fcf3d9a9

Issue #11223: Replace threading._info() by sys.thread_info [#11223]

Victor Stinner victor.stinner@haypocalc.com
date Sat, 30 Apr 2011 14:53:09 +0200
parents ce859b848879
children 28b9702a83d1
files Doc/library/sys.rst Doc/library/threading.rst Doc/whatsnew/3.3.rst Include/pythread.h Lib/_dummy_thread.py Lib/test/test_os.py Lib/test/test_sys.py Lib/test/test_threading.py Lib/test/test_threadsignals.py Lib/threading.py Modules/_threadmodule.c Python/sysmodule.c Python/thread.c
diffstat 13 files changed, 119 insertions(+), 108 deletions(-)[+] [-] Doc/library/sys.rst 29 Doc/library/threading.rst 24 Doc/whatsnew/3.3.rst 8 Include/pythread.h 2 Lib/_dummy_thread.py 3 Lib/test/test_os.py 13 Lib/test/test_sys.py 8 Lib/test/test_threading.py 12 Lib/test/test_threadsignals.py 5 Lib/threading.py 3 Modules/_threadmodule.c 13 Python/sysmodule.c 24 Python/thread.c 83

line wrap: on

line diff

--- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -961,6 +961,35 @@ always available. to a console and Python apps started with :program:pythonw. +.. data:: thread_info +

+ .. data:: tracebacklimit When this variable is set to an integer value, it determines the maximum number

--- a/Doc/library/threading.rst +++ b/Doc/library/threading.rst @@ -175,30 +175,6 @@ This module defines the following functi Availability: Windows, systems with POSIX threads. -.. function:: _info() -

-

-

-

-

- This module also defines the following constant: .. data:: TIMEOUT_MAX

--- a/Doc/whatsnew/3.3.rst +++ b/Doc/whatsnew/3.3.rst @@ -112,11 +112,11 @@ connection when done:: (Contributed by Giampaolo RodolĂ  in :issue:9795) -threading ---------- +sys +--- -* The :mod:threading module has a new :func:~threading._info function which

--- a/Include/pythread.h +++ b/Include/pythread.h @@ -74,7 +74,7 @@ PyAPI_FUNC(void) PyThread_release_lock(P PyAPI_FUNC(size_t) PyThread_get_stacksize(void); PyAPI_FUNC(int) PyThread_set_stacksize(size_t); -PyAPI_FUNC(PyObject*) _PyThread_Info(void); +PyAPI_FUNC(PyObject*) PyThread_GetInfo(void); /* Thread Local Storage (TLS) API */ PyAPI_FUNC(int) PyThread_create_key(void);

--- a/Lib/_dummy_thread.py +++ b/Lib/_dummy_thread.py @@ -149,6 +149,3 @@ def interrupt_main(): else: global _interrupt _interrupt = True - -def info():

--- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -27,15 +27,10 @@ except ImportError:

and unmaintained) linuxthreads threading library. There's an issue

when combining linuxthreads with a failed execv call: see

http://bugs.python.org/issue4970.[](#l6.6)

-USING_LINUXTHREADS = False -if threading:

+if hasattr(sys, 'thread_info') and sys.thread_info.version:

+else:

Tests creating TESTFN

class FileTests(unittest.TestCase):

--- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -474,6 +474,14 @@ class SysModuleTest(unittest.TestCase): if not sys.platform.startswith('win'): self.assertIsInstance(sys.abiflags, str)

+ def test_43581(self): # Can't use sys.stdout, as this is a StringIO object when # the test runs under regrtest.

--- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -719,16 +719,6 @@ class BarrierTests(lock_tests.BarrierTes barriertype = staticmethod(threading.Barrier) -class MiscTests(unittest.TestCase):

- - def test_main(): test.support.run_unittest(LockTests, PyRLockTests, CRLockTests, EventTests, ConditionAsRLockTests, ConditionTests, @@ -736,7 +726,7 @@ def test_main(): ThreadTests, ThreadJoinOnShutdown, ThreadingExceptionTests,

if name == "main":

--- a/Lib/test/test_threadsignals.py +++ b/Lib/test/test_threadsignals.py @@ -14,9 +14,8 @@ if sys.platform[:3] in ('win', 'os2') or process_pid = os.getpid() signalled_all=thread.allocate_lock() -info = thread.info() -USING_PTHREAD_COND = (info['name'] == 'pthread'

+USING_PTHREAD_COND = (sys.thread_info.name == 'pthread'

def registerSignals(for_usr1, for_usr2, for_alrm): usr1 = signal.signal(signal.SIGUSR1, for_usr1)

--- a/Lib/threading.py +++ b/Lib/threading.py @@ -19,7 +19,7 @@ from collections import deque all = ['active_count', 'Condition', 'current_thread', 'enumerate', 'Event', 'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Thread', 'Barrier',

Rename some stuff so "from threading import *" is safe

_start_new_thread = _thread.start_new_thread @@ -31,7 +31,6 @@ try: except AttributeError: _CRLock = None TIMEOUT_MAX = _thread.TIMEOUT_MAX -_info = _thread.info del _thread

--- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -1227,17 +1227,6 @@ requiring allocation in multiples of the (4kB pages are common; using multiples of 4096 for the stack size is\n[](#l11.4) the suggested approach in the absence of more specific information)."); -static PyObject * -thread_info(PyObject *self) -{

-} - -PyDoc_STRVAR(thread_info_doc, -"info() -> dict\n[](#l11.14) -\n[](#l11.15) -Informations about the thread implementation."); - static PyMethodDef thread_methods[] = { {"start_new_thread", (PyCFunction)thread_PyThread_start_new_thread, METH_VARARGS, start_new_doc}, @@ -1259,8 +1248,6 @@ static PyMethodDef thread_methods[] = { METH_NOARGS, _count_doc}, {"stack_size", (PyCFunction)thread_stack_size, METH_VARARGS, stack_size_doc},

--- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -17,6 +17,7 @@ Data members: #include "Python.h" #include "code.h" #include "frameobject.h" +#include "pythread.h" #include "osdefs.h" @@ -1251,20 +1252,21 @@ PyDoc_STR( "\n[](#l12.12) Static objects:\n[](#l12.13) \n[](#l12.14) -float_info -- a dict with information about the float implementation.\n[](#l12.15) +builtin_module_names -- tuple of module names built into this interpreter\n[](#l12.16) +copyright -- copyright notice pertaining to this interpreter\n[](#l12.17) +exec_prefix -- prefix used to find the machine-specific Python library\n[](#l12.18) +executable -- pathname of this Python interpreter\n[](#l12.19) +float_info -- a struct sequence with information about the float implementation.\n[](#l12.20) +float_repr_style -- string indicating the style of repr() output for floats\n[](#l12.21) +hexversion -- version information encoded as a single integer\n[](#l12.22) int_info -- a struct sequence with information about the int implementation.\n[](#l12.23) maxsize -- the largest supported length of containers.\n[](#l12.24) maxunicode -- the largest supported character\n[](#l12.25) -builtin_module_names -- tuple of module names built into this interpreter\n[](#l12.26) +platform -- platform identifier\n[](#l12.27) +prefix -- prefix used to find the Python library\n[](#l12.28) +thread_info -- a struct sequence with information about the thread implementation.\n[](#l12.29) version -- the version of this interpreter as a string\n[](#l12.30) version_info -- version information as a named tuple\n[](#l12.31) -hexversion -- version information encoded as a single integer\n[](#l12.32) -copyright -- copyright notice pertaining to this interpreter\n[](#l12.33) -platform -- platform identifier\n[](#l12.34) -executable -- pathname of this Python interpreter\n[](#l12.35) -prefix -- prefix used to find the Python library\n[](#l12.36) -exec_prefix -- prefix used to find the machine-specific Python library\n[](#l12.37) -float_repr_style -- string indicating the style of repr() output for floats\n[](#l12.38) " ) #ifdef MS_WINDOWS @@ -1611,6 +1613,10 @@ PyObject * PyUnicode_FromString("legacy")); #endif +#ifdef WITH_THREAD

+#endif + #undef SET_SYS_FROM_STRING if (PyErr_Occurred()) return NULL;

--- a/Python/thread.c +++ b/Python/thread.c @@ -7,7 +7,6 @@ #include "Python.h" - #ifndef POSIX_THREADS /* This means pthreads are not implemented in libc headers, hence the macro not present in unistd.h. But they still can be implemented as an external @@ -415,26 +414,51 @@ PyThread_ReInitTLS(void) #endif /* Py_HAVE_NATIVE_TLS */ +PyDoc_STRVAR(threadinfo__doc_, +"sys.thread_info\n[](#l13.16) +\n[](#l13.17) +A struct sequence holding information about the thread implementation."); + +static PyStructSequence_Field threadinfo_fields[] = {

+}; + +static PyStructSequence_Desc threadinfo_desc = {

+}; + +static PyTypeObject ThreadInfoType; + PyObject* -_PyThread_Info(void) +PyThread_GetInfo(void) {

#if (defined(_POSIX_THREADS) && defined(HAVE_CONFSTR) [](#l13.44) && defined(_CS_GNU_LIBPTHREAD_VERSION)) char buffer[255]; int len; #endif

+

value = PyUnicode_FromString(PYTHREAD_NAME);

#ifdef _POSIX_THREADS #ifdef USE_SEMAPHORES @@ -442,30 +466,31 @@ PyObject* #else value = PyUnicode_FromString("mutex+cond"); #endif

+#else

+#endif

-#if defined(HAVE_CONFSTR) && defined(_CS_GNU_LIBPTHREAD_VERSION) +#if (defined(_POSIX_THREADS) && defined(HAVE_CONFSTR) [](#l13.92)

#endif -

- -error:

}