summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_threading.py
diff options
context:
space:
mode:
authorAntoine Pitrou <pitrou@free.fr>2017-10-02 14:42:15 (GMT)
committerGitHub <noreply@github.com>2017-10-02 14:42:15 (GMT)
commit1023dbbcb7f05e76053486ae7ef7f73b4cdc5398 (patch)
tree3588990f6fdc88663ac88814ad02840e4c1856bd /Lib/test/test_threading.py
parente6f62f69f07892b993910ff03c9db3ffa5cb9ca5 (diff)
downloadcpython-1023dbbcb7f05e76053486ae7ef7f73b4cdc5398.zip
cpython-1023dbbcb7f05e76053486ae7ef7f73b4cdc5398.tar.gz
cpython-1023dbbcb7f05e76053486ae7ef7f73b4cdc5398.tar.bz2
bpo-31516: current_thread() should not return a dummy thread at shutdown (#3673)
bpo-31516: current_thread() should not return a dummy thread at shutdown
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r--Lib/test/test_threading.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index f7c3680..6e1ae06 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -547,6 +547,35 @@ class ThreadTests(BaseTestCase):
self.assertEqual(err, b"")
self.assertEqual(data, "Thread-1\nTrue\nTrue\n")
+ def test_main_thread_during_shutdown(self):
+ # bpo-31516: current_thread() should still point to the main thread
+ # at shutdown
+ code = """if 1:
+ import gc, threading
+
+ main_thread = threading.current_thread()
+ assert main_thread is threading.main_thread() # sanity check
+
+ class RefCycle:
+ def __init__(self):
+ self.cycle = self
+
+ def __del__(self):
+ print("GC:",
+ threading.current_thread() is main_thread,
+ threading.main_thread() is main_thread,
+ threading.enumerate() == [main_thread])
+
+ RefCycle()
+ gc.collect() # sanity check
+ x = RefCycle()
+ """
+ _, out, err = assert_python_ok("-c", code)
+ data = out.decode()
+ self.assertEqual(err, b"")
+ self.assertEqual(data.splitlines(),
+ ["GC: True True True"] * 2)
+
def test_tstate_lock(self):
# Test an implementation detail of Thread objects.
started = _thread.allocate_lock()