From fb2b0c3be581c4795719d099db7b913e7ecc53e8 Mon Sep 17 00:00:00 2001 From: fawce Date: Wed, 18 Jul 2012 17:20:31 -0400 Subject: [PATCH] responses to sdiehl code review --- zipline/components/tradesimulation.py | 3 ++- zipline/core/component.py | 10 ++-------- zipline/core/monitor.py | 10 ++++------ zipline/protocol.py | 6 ++---- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/zipline/components/tradesimulation.py b/zipline/components/tradesimulation.py index 08ed1b07..6c761114 100644 --- a/zipline/components/tradesimulation.py +++ b/zipline/components/tradesimulation.py @@ -90,7 +90,8 @@ class TradeSimulationClient(Component): ) self.logger = Logger("Print") - # THIS IS A CLASS! + # N.B. that this is a class, which is instantiated later + # in run_algorithm. The class provides a generator. self.stdout_capture = stdout_only_pipe def do_work(self): diff --git a/zipline/core/component.py b/zipline/core/component.py index 2d2aa94e..841800e1 100644 --- a/zipline/core/component.py +++ b/zipline/core/component.py @@ -269,9 +269,6 @@ class Component(object): # ---------------- # Control Dispatch - # Only run a single iteration here, just before exit. - # This helps ensure that the Monitor - # Running on every iteration ruins performance. # ---------------- assert self.control_in, 'Component does not have a control_in socket' @@ -327,11 +324,8 @@ class Component(object): elif event == CONTROL_PROTOCOL.KILL: self.kill() - # ========= - # Hard Kill - # ========= - - # Just exit. + # In case we didn't receive a ping, send a pre-emptive + # pong to the monitor. elif self.last_ping and time.time() - self.last_ping > 1: # send a ping ahead of schedule pre_pong = time.time() diff --git a/zipline/core/monitor.py b/zipline/core/monitor.py index 33db3e8d..11b91fa8 100644 --- a/zipline/core/monitor.py +++ b/zipline/core/monitor.py @@ -295,12 +295,6 @@ class Controller(object): socks = dict(poller.poll(0)) tic = time.time() - # We break out of this loop if the time between - # sending and receiving the heartbeat is more - # than our poll period. - # if tic - self.ctime > self.period: - # break - if socks.get(self.router) == self.zmq.POLLIN: rawmessage = self.router.recv() @@ -315,6 +309,10 @@ class Controller(object): log.error('Invalid frame', rawmessage) pass + # We break out of this loop if the time between + # sending and receiving the heartbeat is more + # than our poll period. + if tic - self.ctime > self.period: log.info("heartbeat loop timedout: %s" % (tic - self.ctime)) log.info(repr(self.responses)) diff --git a/zipline/protocol.py b/zipline/protocol.py index 3e7b57cf..866e5410 100644 --- a/zipline/protocol.py +++ b/zipline/protocol.py @@ -646,14 +646,12 @@ def LOG_FRAME(payload): def LOG_UNFRAME(msg): """ - Expects a json serialized dictionary in event/payload format. + msg should be a tuple of ('LOG',dict) """ record = msgpack.loads(msg) assert isinstance(record, tuple) assert len(record) == 2 assert record[0] == 'LOG' payload = record[1] - assert payload['e'] == 'log' - assert payload.has_key('p') - return payload['p'] + return payload