diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-06-14 16:55:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-14 16:55:22 (GMT) |
commit | 066e5b1a917ec2134e8997d2cadd815724314252 (patch) | |
tree | 963b0b6d7d2ae0c580aa48da0d1423930bf2a32d /Modules/_threadmodule.c | |
parent | 212646cae6b7c4ddc8d98c8b9b6d39a5f259e864 (diff) | |
download | cpython-066e5b1a917ec2134e8997d2cadd815724314252.zip cpython-066e5b1a917ec2134e8997d2cadd815724314252.tar.gz cpython-066e5b1a917ec2134e8997d2cadd815724314252.tar.bz2 |
bpo-37266: Daemon threads are now denied in subinterpreters (GH-14049)
In a subinterpreter, spawning a daemon thread now raises an
exception. Daemon threads were never supported in subinterpreters.
Previously, the subinterpreter finalization crashed with a Pyton
fatal error if a daemon thread was still running.
* Add _thread._is_main_interpreter()
* threading.Thread.start() now raises RuntimeError if the thread is a
daemon thread and the method is called from a subinterpreter.
* The _thread module now uses Argument Clinic for the new function.
* Use textwrap.dedent() in test_threading.SubinterpThreadingTests
Diffstat (limited to 'Modules/_threadmodule.c')
-rw-r--r-- | Modules/_threadmodule.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index d5e40ef..9ab8e7a 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -8,6 +8,14 @@ #include "structmember.h" /* offsetof */ #include "pythread.h" +#include "clinic/_threadmodule.c.h" + +/*[clinic input] +module _thread +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=be8dbe5cc4b16df7]*/ + + static PyObject *ThreadError; static PyObject *str_dict; @@ -1442,6 +1450,21 @@ PyDoc_STRVAR(excepthook_doc, \n\ Handle uncaught Thread.run() exception."); +/*[clinic input] +_thread._is_main_interpreter + +Return True if the current interpreter is the main Python interpreter. +[clinic start generated code]*/ + +static PyObject * +_thread__is_main_interpreter_impl(PyObject *module) +/*[clinic end generated code: output=7dd82e1728339adc input=cc1eb00fd4598915]*/ +{ + _PyRuntimeState *runtime = &_PyRuntime; + PyInterpreterState *interp = _PyRuntimeState_GetThreadState(runtime)->interp; + return PyBool_FromLong(interp == runtime->interpreters.main); +} + static PyMethodDef thread_methods[] = { {"start_new_thread", (PyCFunction)thread_PyThread_start_new_thread, METH_VARARGS, start_new_doc}, @@ -1471,6 +1494,7 @@ static PyMethodDef thread_methods[] = { METH_NOARGS, _set_sentinel_doc}, {"_excepthook", thread_excepthook, METH_O, excepthook_doc}, + _THREAD__IS_MAIN_INTERPRETER_METHODDEF {NULL, NULL} /* sentinel */ }; |