Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Unified Diff: tools/telemetry/telemetry/core/platform/power_monitor/ippet_power_monitor.py

Issue 444013002: [Telemetry] Ensure we close ippet's handle if anything goes wrong. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/core/platform/power_monitor/ippet_power_monitor.py
diff --git a/tools/telemetry/telemetry/core/platform/power_monitor/ippet_power_monitor.py b/tools/telemetry/telemetry/core/platform/power_monitor/ippet_power_monitor.py
index 4b33f0b805cc303e53c5b5b0acd8e776e649da52..8f43271332bccfb5f59c625e0d389b2c138fb36b 100644
--- a/tools/telemetry/telemetry/core/platform/power_monitor/ippet_power_monitor.py
+++ b/tools/telemetry/telemetry/core/platform/power_monitor/ippet_power_monitor.py
@@ -121,26 +121,28 @@ class IppetPowerMonitor(power_monitor.PowerMonitor):
def StopMonitoringPower(self):
assert self._ippet_handle, (
'Called StopMonitoringPower() before StartMonitoringPower().')
- # Stop IPPET.
- ippet_quit_url = 'http://127.0.0.1:%d/ippet?cmd=quit' % self._ippet_port
- quit_output = urllib2.urlopen(ippet_quit_url).read()
- if quit_output != 'quiting\r\n':
- raise IppetError('Failed to quit IPPET: %s' % quit_output.strip())
- wait_return_code = win32event.WaitForSingleObject(self._ippet_handle, 20000)
- if wait_return_code != win32event.WAIT_OBJECT_0:
- if wait_return_code == win32event.WAIT_TIMEOUT:
- raise IppetError('Timed out waiting for IPPET to close.')
- else:
- raise IppetError('Error code %d while waiting for IPPET to close.' %
- wait_return_code)
- ippet_exit_code = win32process.GetExitCodeProcess(self._ippet_handle)
- if ippet_exit_code == win32con.STILL_ACTIVE:
- raise IppetError('IPPET is still running but should have stopped.')
- elif ippet_exit_code != 0:
- raise IppetError('IPPET closed with exit code %d.' % ippet_exit_code)
- self._ippet_handle.Close()
- self._ippet_handle = None
- self._ippet_port = None
+ try:
+ ippet_quit_url = 'http://127.0.0.1:%d/ippet?cmd=quit' % self._ippet_port
+ quit_output = urllib2.urlopen(ippet_quit_url).read()
+ if quit_output != 'quiting\r\n':
+ raise IppetError('Failed to quit IPPET: %s' % quit_output.strip())
+ wait_return_code = win32event.WaitForSingleObject(self._ippet_handle,
+ 20000)
+ if wait_return_code != win32event.WAIT_OBJECT_0:
+ if wait_return_code == win32event.WAIT_TIMEOUT:
+ raise IppetError('Timed out waiting for IPPET to close.')
+ else:
+ raise IppetError('Error code %d while waiting for IPPET to close.' %
+ wait_return_code)
+ ippet_exit_code = win32process.GetExitCodeProcess(self._ippet_handle)
+ if ippet_exit_code == win32con.STILL_ACTIVE:
+ raise IppetError('IPPET is still running but should have stopped.')
+ elif ippet_exit_code != 0:
+ raise IppetError('IPPET closed with exit code %d.' % ippet_exit_code)
+ finally:
+ self._ippet_handle.Close()
dtu 2014/08/06 19:04:22 Closing the handle just releases the reference, it
+ self._ippet_handle = None
+ self._ippet_port = None
# Read IPPET's log file.
log_file = os.path.join(self._output_dir, 'ippet_log_processes.xls')
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698