| OLD | NEW |
| 1 # Copyright (C) 2011 Google Inc. All rights reserved. | 1 # Copyright (C) 2011 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 def _remove_stale_logs(self): | 152 def _remove_stale_logs(self): |
| 153 """This routine can be overridden by subclasses to try and remove logs | 153 """This routine can be overridden by subclasses to try and remove logs |
| 154 left over from a prior run. This routine should log warnings if the | 154 left over from a prior run. This routine should log warnings if the |
| 155 files cannot be deleted, but should not fail unless failure to | 155 files cannot be deleted, but should not fail unless failure to |
| 156 delete the logs will actually cause start() to fail.""" | 156 delete the logs will actually cause start() to fail.""" |
| 157 # Sometimes logs are open in other processes but they should clear event
ually. | 157 # Sometimes logs are open in other processes but they should clear event
ually. |
| 158 for log_prefix in self._log_prefixes: | 158 for log_prefix in self._log_prefixes: |
| 159 try: | 159 try: |
| 160 self._remove_log_files(self._output_dir, log_prefix) | 160 self._remove_log_files(self._output_dir, log_prefix) |
| 161 except OSError, e: | 161 except OSError as e: |
| 162 _log.warning('Failed to remove old %s %s files' % (self._name, l
og_prefix)) | 162 _log.warning('Failed to remove old %s %s files' % (self._name, l
og_prefix)) |
| 163 | 163 |
| 164 def _spawn_process(self): | 164 def _spawn_process(self): |
| 165 _log.debug('Starting %s server, cmd="%s"' % (self._name, self._start_cmd
)) | 165 _log.debug('Starting %s server, cmd="%s"' % (self._name, self._start_cmd
)) |
| 166 self._process = self._executive.popen(self._start_cmd, | 166 self._process = self._executive.popen(self._start_cmd, |
| 167 env=self._env, | 167 env=self._env, |
| 168 cwd=self._cwd, | 168 cwd=self._cwd, |
| 169 stdout=self._stdout, | 169 stdout=self._stdout, |
| 170 stderr=self._stderr) | 170 stderr=self._stderr) |
| 171 pid = self._process.pid | 171 pid = self._process.pid |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 _log.debug("Server isn't running at all") | 247 _log.debug("Server isn't running at all") |
| 248 self._log_errors_from_subprocess() | 248 self._log_errors_from_subprocess() |
| 249 raise ServerError("Server exited") | 249 raise ServerError("Server exited") |
| 250 | 250 |
| 251 for mapping in self._mappings: | 251 for mapping in self._mappings: |
| 252 s = socket.socket() | 252 s = socket.socket() |
| 253 port = mapping['port'] | 253 port = mapping['port'] |
| 254 try: | 254 try: |
| 255 s.connect(('localhost', port)) | 255 s.connect(('localhost', port)) |
| 256 _log.debug("Server running on %d" % port) | 256 _log.debug("Server running on %d" % port) |
| 257 except IOError, e: | 257 except IOError as e: |
| 258 if e.errno not in (errno.ECONNREFUSED, errno.ECONNRESET): | 258 if e.errno not in (errno.ECONNREFUSED, errno.ECONNRESET): |
| 259 raise | 259 raise |
| 260 _log.debug("Server NOT running on %d: %s" % (port, e)) | 260 _log.debug("Server NOT running on %d: %s" % (port, e)) |
| 261 return False | 261 return False |
| 262 finally: | 262 finally: |
| 263 s.close() | 263 s.close() |
| 264 return True | 264 return True |
| 265 | 265 |
| 266 def _check_that_all_ports_are_available(self): | 266 def _check_that_all_ports_are_available(self): |
| 267 for mapping in self._mappings: | 267 for mapping in self._mappings: |
| 268 s = socket.socket() | 268 s = socket.socket() |
| 269 if not self._platform.is_win(): | 269 if not self._platform.is_win(): |
| 270 s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | 270 s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
| 271 port = mapping['port'] | 271 port = mapping['port'] |
| 272 try: | 272 try: |
| 273 s.bind(('localhost', port)) | 273 s.bind(('localhost', port)) |
| 274 except IOError, e: | 274 except IOError as e: |
| 275 if e.errno in (errno.EALREADY, errno.EADDRINUSE): | 275 if e.errno in (errno.EALREADY, errno.EADDRINUSE): |
| 276 raise ServerError('Port %d is already in use.' % port) | 276 raise ServerError('Port %d is already in use.' % port) |
| 277 elif self._platform.is_win() and e.errno in (errno.WSAEACCES,):
# pylint: disable=E1101 | 277 elif self._platform.is_win() and e.errno in (errno.WSAEACCES,):
# pylint: disable=E1101 |
| 278 raise ServerError('Port %d is already in use.' % port) | 278 raise ServerError('Port %d is already in use.' % port) |
| 279 else: | 279 else: |
| 280 raise | 280 raise |
| 281 finally: | 281 finally: |
| 282 s.close() | 282 s.close() |
| 283 _log.debug('all ports are available') | 283 _log.debug('all ports are available') |
| OLD | NEW |