From 08f7b115acbbf268fb56a3f24e5e376d449bb06a Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Thu, 26 Apr 2012 14:42:38 -0400 Subject: [PATCH] Cleaner exception/shutdown procedures. --- zipline/component.py | 5 +++-- zipline/messaging.py | 4 ++-- zipline/monitor.py | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/zipline/component.py b/zipline/component.py index 1f8ebc1f..d82c8fb9 100644 --- a/zipline/component.py +++ b/zipline/component.py @@ -10,6 +10,7 @@ import uuid import time import socket import gevent +import traceback import humanhash # pyzmq @@ -305,11 +306,11 @@ class Component(object): self._exception = exc exc_type, exc_value, exc_traceback = sys.exc_info() - self.stack_trace = exc_traceback + trace = '\n>>>'.join(traceback.format_exception(exc_type, exc_value, exc_traceback)) exception_frame = CONTROL_FRAME( CONTROL_PROTOCOL.EXCEPTION, - str(exc) + trace ) self.control_out.send(exception_frame) diff --git a/zipline/messaging.py b/zipline/messaging.py index 6cd4154d..fd1875c1 100644 --- a/zipline/messaging.py +++ b/zipline/messaging.py @@ -227,7 +227,7 @@ class Feed(Component): # -- Soft Kill -- elif event == CONTROL_PROTOCOL.SHUTDOWN: - self.done() + self.signal_done() self.shutdown() # -- Hard Kill -- @@ -496,7 +496,7 @@ class BaseTransform(Component): # -- Soft Kill -- elif event == CONTROL_PROTOCOL.SHUTDOWN: - self.done() + self.signal_done() self.shutdown() # -- Hard Kill -- diff --git a/zipline/monitor.py b/zipline/monitor.py index 664bdb6d..915043b4 100644 --- a/zipline/monitor.py +++ b/zipline/monitor.py @@ -425,8 +425,8 @@ class Controller(object): """ Shutdown the system on failure. """ - self.state = CONTROL_STATES.TERMINATE self.logging.error('[Controller] System in exception state, shutting down') + self.shutdown(soft=True) def exception(self, component, failure): universal = self.exception_universal @@ -515,7 +515,7 @@ class Controller(object): return s def do_error_replay(self): - for (component, time), error in self.error_replay: + for (component, time), error in self.error_replay.iteritems(): self.logging.info('[Controller] Error Log for -- %s --:\n%s' % (component, error))