From 52b597f089ab0abcaeb36385515ad080b2a90ecf Mon Sep 17 00:00:00 2001 From: fawce Date: Wed, 25 Jul 2012 12:28:21 -0400 Subject: [PATCH] intersticial commit for scott to pick --- tests/test_exception_handling.py | 13 ++++++++----- zipline/components/tradesimulation.py | 5 ++--- zipline/core/component.py | 7 ++++--- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/test_exception_handling.py b/tests/test_exception_handling.py index 48472ad4..e1564817 100644 --- a/tests/test_exception_handling.py +++ b/tests/test_exception_handling.py @@ -17,7 +17,7 @@ EXTENDED_TIMEOUT = 90 allocator = AddressAllocator(1000) -class FinanceTestCase(TestCase): +class ExceptionTestCase(TestCase): leased_sockets = defaultdict(list) @@ -26,7 +26,8 @@ class FinanceTestCase(TestCase): 'allocator' : allocator, 'sid' : 133, 'devel' : False, - 'results_socket' : allocator.lease(1)[0] + 'results_socket' : allocator.lease(1)[0], + 'simulation_style' : SIMULATION_STYLE.FIXED_SLIPPAGE } self.ctx = zmq.Context() @@ -41,9 +42,8 @@ class FinanceTestCase(TestCase): # Simulation # ---------- - self.zipline_test_config['simulation_style'] = \ - SIMULATION_STYLE.FIXED_SLIPPAGE - self.zipline_test_config['algorithm'] = ExceptionAlgorithm('initialize') + self.zipline_test_config['algorithm'] = \ + ExceptionAlgorithm('initialize') zipline = SimulatedTrading.create_test_zipline( **self.zipline_test_config @@ -58,3 +58,6 @@ class FinanceTestCase(TestCase): # - exception protocol to use prefix/payload as EXCEPT, # and the stack trace # - test exception in handle_data + # - define more zipline failure modes: exception in other + # components, exception in Monitor, etc. write tests + # for those scenarios. diff --git a/zipline/components/tradesimulation.py b/zipline/components/tradesimulation.py index 11b170f6..a20a030c 100644 --- a/zipline/components/tradesimulation.py +++ b/zipline/components/tradesimulation.py @@ -185,14 +185,13 @@ class TradeSimulationClient(Component): # LOG_EXTRA_FIELDS in zipline/protocol.py self.do_op(self.algorithm.handle_data, data) - def exception_callback(self, trace): + def exception_callback(self, exc_type, exc_value, exc_traceback): if self.results_socket: self.out_socket.send("EXCEPTION") def do_op(self, callable_op, *args, **kwargs): """ Wrap a callable operation with the zmq logbook - handler if it exits. Also wrap the invocation of callable - op in a try/except, and relay """ + handler if it exits.""" if self.zmq_out: def inject_event_data(record): diff --git a/zipline/core/component.py b/zipline/core/component.py index b0938b1f..51b439c5 100644 --- a/zipline/core/component.py +++ b/zipline/core/component.py @@ -511,12 +511,13 @@ class Component(object): self._exception = exc exc_type, exc_value, exc_traceback = sys.exc_info() trace = ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback)) + sys.stdout.write(trace) - if hasattr(self, 'exception_callback'): - self.exception_callback(trace) + if hasattr(self, 'exception_callback') and self.exception_callback: + self.exception_callback(exc_type, exc_value, exc_traceback) - if hasattr(self, 'control_out'): + if hasattr(self, 'control_out') and self.control_out: exception_frame = CONTROL_FRAME( CONTROL_PROTOCOL.EXCEPTION, trace