mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
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
This commit is contained in:
parent
212646cae6
commit
066e5b1a91
8 changed files with 113 additions and 29 deletions
|
@ -34,6 +34,7 @@ _start_new_thread = _thread.start_new_thread
|
|||
_allocate_lock = _thread.allocate_lock
|
||||
_set_sentinel = _thread._set_sentinel
|
||||
get_ident = _thread.get_ident
|
||||
_is_main_interpreter = _thread._is_main_interpreter
|
||||
try:
|
||||
get_native_id = _thread.get_native_id
|
||||
_HAVE_THREAD_NATIVE_ID = True
|
||||
|
@ -846,6 +847,11 @@ class Thread:
|
|||
|
||||
if self._started.is_set():
|
||||
raise RuntimeError("threads can only be started once")
|
||||
|
||||
if self.daemon and not _is_main_interpreter():
|
||||
raise RuntimeError("daemon thread are not supported "
|
||||
"in subinterpreters")
|
||||
|
||||
with _active_limbo_lock:
|
||||
_limbo[self] = self
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue