summaryrefslogtreecommitdiff
path: root/Lib/test/test_threading.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-05-05 23:47:09 +0200
committerAntoine Pitrou <solipsis@pitrou.net>2013-05-05 23:47:09 +0200
commit8408cea0cdc0ccd5900acd99a9a51dd9161ae319 (patch)
tree0dcb39ac0cf5fc5e293941763a31bd2472dd004b /Lib/test/test_threading.py
parent39b17c513ae7b9baecdc8292876683647186fee4 (diff)
downloadcpython-git-8408cea0cdc0ccd5900acd99a9a51dd9161ae319.tar.gz
Issue #17094: Clear stale thread states after fork().
Note that this is a potentially disruptive change since it may release some system resources which would otherwise remain perpetually alive (e.g. database connections kept in thread-local storage).
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r--Lib/test/test_threading.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 9ed6ca7a16..ecf22fc749 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -728,6 +728,31 @@ class ThreadJoinOnShutdown(BaseTestCase):
for t in threads:
t.join()
+ @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()")
+ def test_clear_threads_states_after_fork(self):
+ # Issue #17094: check that threads states are cleared after fork()
+
+ # start a bunch of threads
+ threads = []
+ for i in range(16):
+ t = threading.Thread(target=lambda : time.sleep(0.3))
+ threads.append(t)
+ t.start()
+
+ pid = os.fork()
+ if pid == 0:
+ # check that threads states have been cleared
+ if len(sys._current_frames()) == 1:
+ os._exit(0)
+ else:
+ os._exit(1)
+ else:
+ _, status = os.waitpid(pid, 0)
+ self.assertEqual(0, status)
+
+ for t in threads:
+ t.join()
+
class ThreadingExceptionTests(BaseTestCase):
# A RuntimeError should be raised if Thread.start() is called