Commit 00db7c73 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-36719: regrtest closes explicitly WindowsLoadTracker (GH-12965)

Regrtest.finalize() now closes explicitly the WindowsLoadTracker
instance.
parent 837acc19
...@@ -98,6 +98,8 @@ class Regrtest: ...@@ -98,6 +98,8 @@ class Regrtest:
# used by --junit-xml # used by --junit-xml
self.testsuite_xml = None self.testsuite_xml = None
self.win_load_tracker = None
def get_executed(self): def get_executed(self):
return (set(self.good) | set(self.bad) | set(self.skipped) return (set(self.good) | set(self.bad) | set(self.skipped)
| set(self.resource_denieds) | set(self.environment_changed) | set(self.resource_denieds) | set(self.environment_changed)
...@@ -154,9 +156,9 @@ class Regrtest: ...@@ -154,9 +156,9 @@ class Regrtest:
line = f"[{line}] {text}" line = f"[{line}] {text}"
# add the system load prefix: "load avg: 1.80 " # add the system load prefix: "load avg: 1.80 "
if self.getloadavg: load_avg = self.getloadavg()
load_avg_1min = self.getloadavg() if load_avg is not None:
line = f"load avg: {load_avg_1min:.2f} {line}" line = f"load avg: {load_avg:.2f} {line}"
# add the timestamp prefix: "0:01:05 " # add the timestamp prefix: "0:01:05 "
test_time = time.monotonic() - self.start_time test_time = time.monotonic() - self.start_time
...@@ -490,6 +492,10 @@ class Regrtest: ...@@ -490,6 +492,10 @@ class Regrtest:
self.run_tests_sequential() self.run_tests_sequential()
def finalize(self): 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_filename:
if self.next_single_test: if self.next_single_test:
with open(self.next_single_filename, 'w') as fp: with open(self.next_single_filename, 'w') as fp:
...@@ -560,6 +566,15 @@ class Regrtest: ...@@ -560,6 +566,15 @@ class Regrtest:
with support.temp_cwd(test_cwd, quiet=True): with support.temp_cwd(test_cwd, quiet=True):
self._main(tests, kwargs) 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): def _main(self, tests, kwargs):
if self.ns.huntrleaks: if self.ns.huntrleaks:
warmup, repetitions, _ = self.ns.huntrleaks warmup, repetitions, _ = self.ns.huntrleaks
...@@ -591,23 +606,17 @@ class Regrtest: ...@@ -591,23 +606,17 @@ class Regrtest:
self.list_cases() self.list_cases()
sys.exit(0) sys.exit(0)
self.getloadavg = None
# If we're on windows and this is the parent runner (not a worker), # If we're on windows and this is the parent runner (not a worker),
# report the load average. # track the load average.
if hasattr(os, 'getloadavg'): if sys.platform == 'win32' and (self.ns.worker_args is None):
def getloadavg_1m():
return os.getloadavg()[0]
self.getloadavg = getloadavg_1m
elif sys.platform == 'win32' and (self.ns.worker_args is None):
from test.libregrtest.win_utils import WindowsLoadTracker from test.libregrtest.win_utils import WindowsLoadTracker
try: try:
load_tracker = WindowsLoadTracker() self.win_load_tracker = WindowsLoadTracker()
self.getloadavg = load_tracker.getloadavg
except FileNotFoundError as error: except FileNotFoundError as error:
# Windows IoT Core and Windows Nano Server do not provide # Windows IoT Core and Windows Nano Server do not provide
# typeperf.exe for x64, x86 or ARM # 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.run_tests()
self.display_result() self.display_result()
......
...@@ -60,9 +60,15 @@ class WindowsLoadTracker(): ...@@ -60,9 +60,15 @@ class WindowsLoadTracker():
# Close our copy of the write end of the pipe # Close our copy of the write end of the pipe
os.close(command_stdout) os.close(command_stdout)
def __del__(self): def close(self):
if self.p is None:
return
self.p.kill() self.p.kill()
self.p.wait() self.p.wait()
self.p = None
def __del__(self):
self.close()
def read_output(self): def read_output(self):
import _winapi import _winapi
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment