Skip to content

Commit 15054c1

Browse files
committed
Issue python#20526, python#19466: Revert changes of issue python#19466 which introduces a
regression: don't clear anymore the state of Python threads early during the Python shutdown.
1 parent e755fba commit 15054c1

3 files changed

Lines changed: 9 additions & 64 deletions

File tree

Lib/test/test_threading.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -616,51 +616,6 @@ def test_BoundedSemaphore_limit(self):
616616
t.join()
617617
self.assertRaises(ValueError, bs.release)
618618

619-
def test_locals_at_exit(self):
620-
# Issue #19466: thread locals must not be deleted before destructors
621-
# are called
622-
rc, out, err = assert_python_ok("-c", """if 1:
623-
import threading
624-
625-
class Atexit:
626-
def __del__(self):
627-
print("thread_dict.atexit = %r" % thread_dict.atexit)
628-
629-
thread_dict = threading.local()
630-
thread_dict.atexit = "atexit"
631-
632-
atexit = Atexit()
633-
""")
634-
self.assertEqual(out.rstrip(), b"thread_dict.atexit = 'atexit'")
635-
636-
def test_warnings_at_exit(self):
637-
# Issue #19466: try to call most destructors at Python shutdown before
638-
# destroying Python thread states
639-
filename = __file__
640-
rc, out, err = assert_python_ok("-Wd", "-c", """if 1:
641-
import time
642-
import threading
643-
644-
def open_sleep():
645-
# a warning will be emitted when the open file will be
646-
# destroyed (without being explicitly closed) while the daemon
647-
# thread is destroyed
648-
fileobj = open(%a, 'rb')
649-
start_event.set()
650-
time.sleep(60.0)
651-
652-
start_event = threading.Event()
653-
654-
thread = threading.Thread(target=open_sleep)
655-
thread.daemon = True
656-
thread.start()
657-
658-
# wait until the thread started
659-
start_event.wait()
660-
""" % filename)
661-
self.assertRegex(err.rstrip(),
662-
b"^sys:1: ResourceWarning: unclosed file ")
663-
664619
@cpython_only
665620
def test_frame_tstate_tracing(self):
666621
# Issue #14432: Crash when a generator is created in a C thread that is
@@ -786,10 +741,6 @@ def test_4_daemon_threads(self):
786741
import sys
787742
import time
788743
import threading
789-
import warnings
790-
791-
# ignore "unclosed file ..." warnings
792-
warnings.filterwarnings('ignore', '', ResourceWarning)
793744
794745
thread_has_run = set()
795746

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Release date: 2014-02-23
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #20526: Revert changes of issue #19466 which introduces a regression:
14+
don't clear anymore the state of Python threads early during the Python
15+
shutdown.
16+
1317
- Issue #20595: Make getargs.c C89 compliant.
1418

1519
Library

Python/pythonrun.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,11 @@ Py_Finalize(void)
582582
_Py_Finalizing = tstate;
583583
initialized = 0;
584584

585-
/* Destroy the state of all threads except of the current thread: in
586-
practice, only daemon threads should still be alive. Clear frames of
587-
other threads to call objects destructor. Destructors will be called in
588-
the current Python thread. Since _Py_Finalizing has been set, no other
589-
Python threads can lock the GIL at this point (if they try, they will
590-
exit immediately). */
591-
_PyThreadState_DeleteExcept(tstate);
585+
/* Flush stdout+stderr */
586+
flush_std_files();
587+
588+
/* Disable signal handling */
589+
PyOS_FiniInterrupts();
592590

593591
/* Collect garbage. This may call finalizers; it's nice to call these
594592
* before all modules are destroyed.
@@ -603,21 +601,13 @@ Py_Finalize(void)
603601
* XXX I haven't seen a real-life report of either of these.
604602
*/
605603
PyGC_Collect();
606-
607604
#ifdef COUNT_ALLOCS
608605
/* With COUNT_ALLOCS, it helps to run GC multiple times:
609606
each collection might release some types from the type
610607
list, so they become garbage. */
611608
while (PyGC_Collect() > 0)
612609
/* nothing */;
613610
#endif
614-
615-
/* Flush stdout+stderr */
616-
flush_std_files();
617-
618-
/* Disable signal handling */
619-
PyOS_FiniInterrupts();
620-
621611
/* Destroy all modules */
622612
PyImport_Cleanup();
623613

0 commit comments

Comments
 (0)