clean up cruft and fix bugs from timeout rename

This commit is contained in:
scottsanderson
2012-08-23 13:09:31 -04:00
parent 567659d058
commit 22523b5c12
4 changed files with 9 additions and 27 deletions
+2 -2
View File
@@ -160,7 +160,7 @@ class ExceptionTestCase(TestCase):
output, _ = drain_zipline(self, zipline)
self.assertEqual(output[-1]['prefix'], 'EXCEPTION')
payload = output[-1]['payload']
self.assertEqual(payload['name'],'Timeout')
self.assertEqual(payload['name'],'TimeoutException')
self.assertEqual(payload['message'], 'Call to initialize timed out')
def test_heartbeat(self):
@@ -186,6 +186,6 @@ class ExceptionTestCase(TestCase):
# Assert that the last message is a timeout exception.
self.assertEqual(output[-1]['prefix'], 'EXCEPTION')
payload = output[-1]['payload']
self.assertEqual(payload['name'],'Timeout')
self.assertEqual(payload['name'],'TimeoutException')
self.assertEqual(payload['message'], 'Too much time spent in handle_data call')
-18
View File
@@ -167,9 +167,6 @@ class PerformanceTracker(object):
self.last_dict = None
self.exceeded_max_loss = False
self.results_socket = None
self.results_addr = None
# this performance period will span the entire simulation.
self.cumulative_performance = PerformancePeriod(
# initial positions are empty
@@ -229,21 +226,6 @@ class PerformanceTracker(object):
def get_portfolio(self):
return self.cumulative_performance.as_portfolio()
def open(self, context):
if self.results_addr:
sock = context.socket(zmq.PUSH)
sock.connect(self.results_addr)
self.results_socket = sock
else:
log.warn("Not streaming results because no results socket given")
def publish_to(self, results_addr):
"""
Publish the performance results asynchronously to a
socket.
"""
self.results_socket = results_addr
def to_dict(self):
"""
Creates a dictionary representing the state of this tracker.
+4 -4
View File
@@ -6,7 +6,7 @@ from numbers import Integral
from itertools import groupby
from zipline import ndict
from zipline.utils.timeout import timeout, heartbeat, Timeout
from zipline.utils.timeout import Heartbeat, Timeout
from zipline.gens.transform import StatefulTransform
from zipline.finance.trading import TransactionSimulator
@@ -85,7 +85,7 @@ class TradeSimulationClient(object):
"""
# Simulate filling any open orders made by the previous run of
# the user's algorithm. Sets the TRANSACTION field to true on any
# the user's algorithm. Fills the Transaction field on any
# event that results in a filled order.
with_filled_orders = self.ordering_client.transform(stream_in)
@@ -141,7 +141,7 @@ class AlgorithmSimulator(object):
# Context manager that calls log_heartbeats every HEARTBEAT_INTERVAL
# seconds, raising an exception after MAX_HEARTBEATS
self.heartbeat_monitor = heartbeat(
self.heartbeat_monitor = Heartbeat(
HEARTBEAT_INTERVAL,
MAX_HEARTBEAT_INTERVALS,
frame_handler=log_heartbeats,
@@ -216,7 +216,7 @@ class AlgorithmSimulator(object):
with self.processor.threadbound(), self.stdout_capture(Logger('Print'),''):
# Call user's initialize method with a timeout.
with timeout(INIT_TIMEOUT, message="Call to initialize timed out"):
with Timeout(INIT_TIMEOUT, message="Call to initialize timed out"):
self.algo.initialize()
# Group together events with the same dt field. This depends on the
+3 -3
View File
@@ -21,7 +21,7 @@ class Timeout(object):
as a decorator to apply a static timeout to a function, or as
a context manager to dynamically add a timeout to a code block.
"""
def __init__(self, seconds, message=''):
self.seconds = seconds
self.message = message
@@ -29,7 +29,7 @@ class Timeout(object):
assert seconds > 0, "Timeout must be greater than 0"
def handler(self, signum, frame):
raise Timeout(frame, self.message)
raise TimeoutException(frame, self.message)
def __call__(self, fn):
@@ -91,7 +91,7 @@ class Heartbeat(object):
self.frame_handler(self.count, frame)
if self.count >= self.max_intervals:
raise Timeout(frame, self.timeout_message)
raise TimeoutException(frame, self.timeout_message)
def __call__(self, fn):