diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-04-26 09:12:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-26 09:12:26 (GMT) |
commit | 00db7c73af4f60df61e9df87cde7401c3ed9df69 (patch) | |
tree | 60fe30b3ead904dec6891760e6e51419bb74fe5d | |
parent | 837acc1957d86ca950433f5064fd06d09b57d23b (diff) | |
download | cpython-00db7c73af4f60df61e9df87cde7401c3ed9df69.zip cpython-00db7c73af4f60df61e9df87cde7401c3ed9df69.tar.gz cpython-00db7c73af4f60df61e9df87cde7401c3ed9df69.tar.bz2 |
bpo-36719: regrtest closes explicitly WindowsLoadTracker (GH-12965)
Regrtest.finalize() now closes explicitly the WindowsLoadTracker
instance.
-rw-r--r-- | Lib/test/libregrtest/main.py | 35 | ||||
-rw-r--r-- | Lib/test/libregrtest/win_utils.py | 8 |
2 files changed, 29 insertions, 14 deletions
diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index 691fb52..c19ea44 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -98,6 +98,8 @@ class Regrtest: # used by --junit-xml self.testsuite_xml = None + self.win_load_tracker = None + def get_executed(self): return (set(self.good) | set(self.bad) | set(self.skipped) | set(self.resource_denieds) | set(self.environment_changed) @@ -154,9 +156,9 @@ class Regrtest: line = f"[{line}] {text}" # add the system load prefix: "load avg: 1.80 " - if self.getloadavg: - load_avg_1min = self.getloadavg() - line = f"load avg: {load_avg_1min:.2f} {line}" + load_avg = self.getloadavg() + if load_avg is not None: + line = f"load avg: {load_avg:.2f} {line}" # add the timestamp prefix: "0:01:05 " test_time = time.monotonic() - self.start_time @@ -490,6 +492,10 @@ class Regrtest: self.run_tests_sequential() def finalize(self): + if self.win_load_tracker is not None: + self.win_load_tracker.close() + self.win_load_tracker = None + if self.next_single_filename: if self.next_single_test: with open(self.next_single_filename, 'w') as fp: @@ -560,6 +566,15 @@ class Regrtest: with support.temp_cwd(test_cwd, quiet=True): self._main(tests, kwargs) + def getloadavg(self): + if self.win_load_tracker is not None: + return self.win_load_tracker.getloadavg() + + if hasattr(os, 'getloadavg'): + return os.getloadavg()[0] + + return None + def _main(self, tests, kwargs): if self.ns.huntrleaks: warmup, repetitions, _ = self.ns.huntrleaks @@ -591,23 +606,17 @@ class Regrtest: self.list_cases() sys.exit(0) - self.getloadavg = None # If we're on windows and this is the parent runner (not a worker), - # report the load average. - if hasattr(os, 'getloadavg'): - def getloadavg_1m(): - return os.getloadavg()[0] - self.getloadavg = getloadavg_1m - elif sys.platform == 'win32' and (self.ns.worker_args is None): + # track the load average. + if sys.platform == 'win32' and (self.ns.worker_args is None): from test.libregrtest.win_utils import WindowsLoadTracker try: - load_tracker = WindowsLoadTracker() - self.getloadavg = load_tracker.getloadavg + self.win_load_tracker = WindowsLoadTracker() except FileNotFoundError as error: # Windows IoT Core and Windows Nano Server do not provide # typeperf.exe for x64, x86 or ARM - print('Failed to create WindowsLoadTracker: {}'.format(error)) + print(f'Failed to create WindowsLoadTracker: {error}') self.run_tests() self.display_result() diff --git a/Lib/test/libregrtest/win_utils.py b/Lib/test/libregrtest/win_utils.py index ca27f36..adfe278 100644 --- a/Lib/test/libregrtest/win_utils.py +++ b/Lib/test/libregrtest/win_utils.py @@ -60,9 +60,15 @@ class WindowsLoadTracker(): # Close our copy of the write end of the pipe os.close(command_stdout) - def __del__(self): + def close(self): + if self.p is None: + return self.p.kill() self.p.wait() + self.p = None + + def __del__(self): + self.close() def read_output(self): import _winapi |