summaryrefslogtreecommitdiffstats
path: root/Lib/test/regrtest.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-07-15 20:15:38 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-07-15 20:15:38 (GMT)
commit428bc6c48f41123149ddf1c3589fbe548cc38c48 (patch)
tree80f470fa46e60653994c790718621b2dfb56c580 /Lib/test/regrtest.py
parent91fe8157fd3518fcf7c2f7cd7bd247131e8e839f (diff)
parentc081c0c6a0c917de72b7d7944c5316174717d56d (diff)
downloadcpython-428bc6c48f41123149ddf1c3589fbe548cc38c48.zip
cpython-428bc6c48f41123149ddf1c3589fbe548cc38c48.tar.gz
cpython-428bc6c48f41123149ddf1c3589fbe548cc38c48.tar.bz2
Issue #12573: Add resource checks for dangling Thread and Process objects.
Diffstat (limited to 'Lib/test/regrtest.py')
-rwxr-xr-xLib/test/regrtest.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 528f46a..4444f57 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -182,6 +182,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
@@ -930,7 +939,8 @@ class saved_test_environment:
'os.environ', 'sys.path', 'sys.path_hooks', '__import__',
'warnings.filters', 'asyncore.socket_map',
'logging._handlers', 'logging._handlerList', 'sys.gettrace',
- 'sys.warnoptions')
+ 'sys.warnoptions', 'threading._dangling',
+ 'multiprocessing.process._dangling')
def get_sys_argv(self):
return id(sys.argv), sys.argv, sys.argv[:]
@@ -1023,6 +1033,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('.', '_')