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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 if not self._running_inline: | 239 if not self._running_inline: |
240 super(_Worker, self).start() | 240 super(_Worker, self).start() |
241 | 241 |
242 def run(self): | 242 def run(self): |
243 if not self.host: | 243 if not self.host: |
244 self.host = Host() | 244 self.host = Host() |
245 if not self._running_inline: | 245 if not self._running_inline: |
246 self._set_up_logging() | 246 self._set_up_logging() |
247 | 247 |
248 worker = self._worker | 248 worker = self._worker |
249 exception_msg = "" | |
250 _log.debug("%s starting" % self.name) | 249 _log.debug("%s starting" % self.name) |
251 self._running = True | 250 self._running = True |
252 | 251 |
253 try: | 252 try: |
254 if hasattr(worker, 'start'): | 253 if hasattr(worker, 'start'): |
255 worker.start() | 254 worker.start() |
256 while self._running: | 255 while self._running: |
257 message = self._messages_to_worker.get() | 256 message = self._messages_to_worker.get() |
258 if message.from_user: | 257 if message.from_user: |
259 worker.handle(message.name, message.src, *message.args) | 258 worker.handle(message.name, message.src, *message.args) |
260 self._yield_to_manager() | 259 self._yield_to_manager() |
261 else: | 260 else: |
262 assert message.name == 'stop', 'bad message %s' % repr(messa
ge) | 261 assert message.name == 'stop', 'bad message %s' % repr(messa
ge) |
263 break | 262 break |
264 | 263 |
265 _log.debug("%s exiting" % self.name) | 264 _log.debug("%s exiting" % self.name) |
266 except Queue.Empty: | 265 except Queue.Empty: |
267 assert False, '%s: ran out of messages in worker queue.' % self.name | 266 assert False, '%s: ran out of messages in worker queue.' % self.name |
268 except KeyboardInterrupt as e: | 267 except KeyboardInterrupt: |
269 self._raise(sys.exc_info()) | 268 self._raise(sys.exc_info()) |
270 except Exception as e: | 269 except Exception: |
271 self._raise(sys.exc_info()) | 270 self._raise(sys.exc_info()) |
272 finally: | 271 finally: |
273 try: | 272 try: |
274 if hasattr(worker, 'stop'): | 273 if hasattr(worker, 'stop'): |
275 worker.stop() | 274 worker.stop() |
276 finally: | 275 finally: |
277 self._post(name='done', args=(), from_user=False) | 276 self._post(name='done', args=(), from_user=False) |
278 self._close() | 277 self._close() |
279 | 278 |
280 def stop_running(self): | 279 def stop_running(self): |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 322 |
324 class _WorkerLogHandler(logging.Handler): | 323 class _WorkerLogHandler(logging.Handler): |
325 | 324 |
326 def __init__(self, worker): | 325 def __init__(self, worker): |
327 logging.Handler.__init__(self) | 326 logging.Handler.__init__(self) |
328 self._worker = worker | 327 self._worker = worker |
329 self.setLevel(worker.log_level) | 328 self.setLevel(worker.log_level) |
330 | 329 |
331 def emit(self, record): | 330 def emit(self, record): |
332 self._worker.log_messages.append(record) | 331 self._worker.log_messages.append(record) |
OLD | NEW |