mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
bpo-44584: Deprecate PYTHONTHREADDEBUG env var (GH-27065)
The threading debug (PYTHONTHREADDEBUG environment variable) is deprecated in Python 3.10 and will be removed in Python 3.12. This feature requires a debug build of Python.
This commit is contained in:
parent
938e84b4fa
commit
4d77691172
7 changed files with 49 additions and 1 deletions
|
@ -962,10 +962,12 @@ Debug-mode variables
|
||||||
|
|
||||||
.. envvar:: PYTHONTHREADDEBUG
|
.. envvar:: PYTHONTHREADDEBUG
|
||||||
|
|
||||||
If set, Python will print threading debug info.
|
If set, Python will print threading debug info into stdout.
|
||||||
|
|
||||||
Need a :ref:`debug build of Python <debug-build>`.
|
Need a :ref:`debug build of Python <debug-build>`.
|
||||||
|
|
||||||
|
.. deprecated-removed:: 3.10 3.12
|
||||||
|
|
||||||
|
|
||||||
.. envvar:: PYTHONDUMPREFS
|
.. envvar:: PYTHONDUMPREFS
|
||||||
|
|
||||||
|
|
|
@ -1691,6 +1691,11 @@ Deprecated
|
||||||
* NPN features like :meth:`ssl.SSLSocket.selected_npn_protocol` and
|
* NPN features like :meth:`ssl.SSLSocket.selected_npn_protocol` and
|
||||||
:meth:`ssl.SSLContext.set_npn_protocols` are replaced by ALPN.
|
:meth:`ssl.SSLContext.set_npn_protocols` are replaced by ALPN.
|
||||||
|
|
||||||
|
* The threading debug (:envvar:`PYTHONTHREADDEBUG` environment variable) is
|
||||||
|
deprecated in Python 3.10 and will be removed in Python 3.12. This feature
|
||||||
|
requires a :ref:`debug build of Python <debug-build>`.
|
||||||
|
(Contributed by Victor Stinner in :issue:`44584`.)
|
||||||
|
|
||||||
.. _whatsnew310-removed:
|
.. _whatsnew310-removed:
|
||||||
|
|
||||||
Removed
|
Removed
|
||||||
|
|
|
@ -32,6 +32,9 @@ from test import support
|
||||||
# on platforms known to behave badly.
|
# on platforms known to behave badly.
|
||||||
platforms_to_skip = ('netbsd5', 'hp-ux11')
|
platforms_to_skip = ('netbsd5', 'hp-ux11')
|
||||||
|
|
||||||
|
# Is Python built with Py_DEBUG macro defined?
|
||||||
|
Py_DEBUG = hasattr(sys, 'gettotalrefcount')
|
||||||
|
|
||||||
|
|
||||||
def restore_default_excepthook(testcase):
|
def restore_default_excepthook(testcase):
|
||||||
testcase.addCleanup(setattr, threading, 'excepthook', threading.excepthook)
|
testcase.addCleanup(setattr, threading, 'excepthook', threading.excepthook)
|
||||||
|
@ -915,6 +918,16 @@ class ThreadTests(BaseTestCase):
|
||||||
threading.Thread(target=noop).start()
|
threading.Thread(target=noop).start()
|
||||||
# Thread.join() is not called
|
# Thread.join() is not called
|
||||||
|
|
||||||
|
@unittest.skipUnless(Py_DEBUG, 'need debug build (Py_DEBUG)')
|
||||||
|
def test_debug_deprecation(self):
|
||||||
|
# bpo-44584: The PYTHONTHREADDEBUG environment variable is deprecated
|
||||||
|
rc, out, err = assert_python_ok("-Wdefault", "-c", "pass",
|
||||||
|
PYTHONTHREADDEBUG="1")
|
||||||
|
msg = (b'DeprecationWarning: The threading debug '
|
||||||
|
b'(PYTHONTHREADDEBUG environment variable) '
|
||||||
|
b'is deprecated and will be removed in Python 3.12')
|
||||||
|
self.assertIn(msg, err)
|
||||||
|
|
||||||
|
|
||||||
class ThreadJoinOnShutdown(BaseTestCase):
|
class ThreadJoinOnShutdown(BaseTestCase):
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
The threading debug (:envvar:`PYTHONTHREADDEBUG` environment variable) is
|
||||||
|
deprecated in Python 3.10 and will be removed in Python 3.12. This feature
|
||||||
|
requires a debug build of Python. Patch by Victor Stinner.
|
|
@ -550,6 +550,7 @@ if Python was configured with the
|
||||||
\fB\--with-pydebug\fP build option.
|
\fB\--with-pydebug\fP build option.
|
||||||
.IP PYTHONTHREADDEBUG
|
.IP PYTHONTHREADDEBUG
|
||||||
If this environment variable is set, Python will print threading debug info.
|
If this environment variable is set, Python will print threading debug info.
|
||||||
|
The feature is deprecated in Python 3.10 and will be removed in Python 3.12.
|
||||||
.IP PYTHONDUMPREFS
|
.IP PYTHONDUMPREFS
|
||||||
If this environment variable is set, Python will dump objects and reference
|
If this environment variable is set, Python will dump objects and reference
|
||||||
counts still alive after shutting down the interpreter.
|
counts still alive after shutting down the interpreter.
|
||||||
|
|
|
@ -1057,6 +1057,8 @@ pyinit_main_reconfigure(PyThreadState *tstate)
|
||||||
static PyStatus
|
static PyStatus
|
||||||
init_interp_main(PyThreadState *tstate)
|
init_interp_main(PyThreadState *tstate)
|
||||||
{
|
{
|
||||||
|
extern void _PyThread_debug_deprecation(void);
|
||||||
|
|
||||||
assert(!_PyErr_Occurred(tstate));
|
assert(!_PyErr_Occurred(tstate));
|
||||||
|
|
||||||
PyStatus status;
|
PyStatus status;
|
||||||
|
@ -1158,6 +1160,9 @@ init_interp_main(PyThreadState *tstate)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Warn about PYTHONTHREADDEBUG deprecation
|
||||||
|
_PyThread_debug_deprecation();
|
||||||
|
|
||||||
assert(!_PyErr_Occurred(tstate));
|
assert(!_PyErr_Occurred(tstate));
|
||||||
|
|
||||||
return _PyStatus_OK();
|
return _PyStatus_OK();
|
||||||
|
|
|
@ -75,6 +75,25 @@ PyThread_init_thread(void)
|
||||||
PyThread__init_thread();
|
PyThread__init_thread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_PyThread_debug_deprecation(void)
|
||||||
|
{
|
||||||
|
#ifdef Py_DEBUG
|
||||||
|
if (thread_debug) {
|
||||||
|
// Flush previous dprintf() logs
|
||||||
|
fflush(stdout);
|
||||||
|
if (PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||||
|
"The threading debug (PYTHONTHREADDEBUG environment "
|
||||||
|
"variable) is deprecated and will be removed "
|
||||||
|
"in Python 3.12",
|
||||||
|
0))
|
||||||
|
{
|
||||||
|
_PyErr_WriteUnraisableMsg("at Python startup", NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(_POSIX_THREADS)
|
#if defined(_POSIX_THREADS)
|
||||||
# define PYTHREAD_NAME "pthread"
|
# define PYTHREAD_NAME "pthread"
|
||||||
# include "thread_pthread.h"
|
# include "thread_pthread.h"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue