@@ -2011,6 +2011,14 @@ def modules_cleanup(oldmodules): |
|
|
2011 |
2011 |
#======================================================================= |
2012 |
2012 |
# Threading support to prevent reporting refleaks when running regrtest.py -R |
2013 |
2013 |
|
|
2014 |
+# Flag used by saved_test_environment of test.libregrtest.save_env, |
|
2015 |
+# to check if a test modified the environment. The flag should be set to False |
|
2016 |
+# before running a new test. |
|
2017 |
+# |
|
2018 |
+# For example, threading_cleanup() sets the flag is the function fails |
|
2019 |
+# to cleanup threads. |
|
2020 |
+environment_altered = False |
|
2021 |
+ |
2014 |
2022 |
# NOTE: we use thread._count() rather than threading.enumerate() (or the |
2015 |
2023 |
# moral equivalent thereof) because a threading.Thread object is still alive |
2016 |
2024 |
# until its __bootstrap() method has returned, even after it has been |
@@ -2026,6 +2034,8 @@ def threading_setup(): |
|
|
2026 |
2034 |
return 1, () |
2027 |
2035 |
|
2028 |
2036 |
def threading_cleanup(*original_values): |
|
2037 |
+global environment_altered |
|
2038 |
+ |
2029 |
2039 |
if not _thread: |
2030 |
2040 |
return |
2031 |
2041 |
_MAX_COUNT = 100 |
@@ -2037,6 +2047,8 @@ def threading_cleanup(*original_values): |
|
|
2037 |
2047 |
time.sleep(0.01) |
2038 |
2048 |
gc_collect() |
2039 |
2049 |
else: |
|
2050 |
+environment_altered = True |
|
2051 |
+ |
2040 |
2052 |
dt = time.monotonic() - t0 |
2041 |
2053 |
print("Warning -- threading_cleanup() failed to cleanup %s threads " |
2042 |
2054 |
"after %.0f sec (count: %s, dangling: %s)" |