diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-07-15 20:12:24 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-07-15 20:12:24 (GMT) |
commit | c081c0c6a0c917de72b7d7944c5316174717d56d (patch) | |
tree | 184657849382db7dec5904be11d3d44895f6a16c /Lib/test | |
parent | b8298a01e6fefec9b0b64fd6915e57fc246b9a55 (diff) | |
download | cpython-c081c0c6a0c917de72b7d7944c5316174717d56d.zip cpython-c081c0c6a0c917de72b7d7944c5316174717d56d.tar.gz cpython-c081c0c6a0c917de72b7d7944c5316174717d56d.tar.bz2 |
Issue #12573: Add resource checks for dangling Thread and Process objects.
Diffstat (limited to 'Lib/test')
-rwxr-xr-x | Lib/test/regrtest.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 14fa005..8ca7f6c 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -172,6 +172,15 @@ import unittest import warnings from inspect import isabstract +try: + import threading +except ImportError: + threading = None +try: + import multiprocessing.process +except ImportError: + multiprocessing = None + # Some times __path__ and __file__ are not absolute (e.g. while running from # Lib/) and, if we change the CWD to run the tests in a temporary dir, some @@ -864,7 +873,8 @@ class saved_test_environment: 'os.environ', 'sys.path', 'sys.path_hooks', '__import__', 'warnings.filters', 'asyncore.socket_map', 'logging._handlers', 'logging._handlerList', - 'sys.warnoptions') + 'sys.warnoptions', 'threading._dangling', + 'multiprocessing.process._dangling') def get_sys_argv(self): return id(sys.argv), sys.argv, sys.argv[:] @@ -952,6 +962,31 @@ class saved_test_environment: sys.warnoptions = saved_options[1] sys.warnoptions[:] = saved_options[2] + # Controlling dangling references to Thread objects can make it easier + # to track reference leaks. + def get_threading__dangling(self): + if not threading: + return None + # This copies the weakrefs without making any strong reference + return threading._dangling.copy() + def restore_threading__dangling(self, saved): + if not threading: + return + threading._dangling.clear() + threading._dangling.update(saved) + + # Same for Process objects + def get_multiprocessing_process__dangling(self): + if not multiprocessing: + return None + # This copies the weakrefs without making any strong reference + return multiprocessing.process._dangling.copy() + def restore_multiprocessing_process__dangling(self, saved): + if not multiprocessing: + return + multiprocessing.process._dangling.clear() + multiprocessing.process._dangling.update(saved) + def resource_info(self): for name in self.resources: method_suffix = name.replace('.', '_') |