diff --git a/zipline/core/component.py b/zipline/core/component.py index df3de619..2d0619ce 100644 --- a/zipline/core/component.py +++ b/zipline/core/component.py @@ -357,7 +357,7 @@ class Component(object): #notify internal work look that we're done self.done = True # TODO: use state flag - log.info("[%s] DONE" % self.get_id) + #log.info("[%s] DONE" % self.get_id) # ----------- # Messaging diff --git a/zipline/core/host.py b/zipline/core/host.py index 3320bfbc..96ab5c05 100644 --- a/zipline/core/host.py +++ b/zipline/core/host.py @@ -100,11 +100,11 @@ class ComponentHost(Component): self.sockets.append(self.sync_socket) def open(self): - log.info('== Roll Call ==\n') + log.info('== Roll Call ==') for component in self.components.itervalues(): log.info(component) - log.info('== End Roll Call ==\n') + log.info('== End Roll Call ==') for component in self.components.itervalues(): self.launch_component(component) diff --git a/zipline/core/monitor.py b/zipline/core/monitor.py index eafa07bb..c274df20 100644 --- a/zipline/core/monitor.py +++ b/zipline/core/monitor.py @@ -7,106 +7,13 @@ import gevent_zeromq from collections import OrderedDict +from zipline.utils.gpoll import _Poller as GeventPoller from zipline.protocol import CONTROL_PROTOCOL, CONTROL_FRAME, \ CONTROL_UNFRAME, CONTROL_STATES, INVALID_CONTROL_FRAME \ -states = CONTROL_STATES - -from zipline.utils.gpoll import _Poller as GeventPoller - -# Roll Call ( Discovery ) -# ----------------------- -# -# Controller ( 'foo', 'bar', 'fizz', 'pop' ) -# ------------------ -# | | | | -# +---+ -# | 0 | ? ? ? -# +---+ -# | -# IDENTITY: foo -# get message: PROTOCOL.HEARTBEAT -# reply with PROTOCOL.OK -# -# Controller topology = ( 'foo', 'bar', 'fizz', 'pop' ) -# 'foo' in topology = YES -> -# track 'foo' -# ------------------ -# | | | | -# +---+ -# | 1 | ? ? ? -# +---+ - -# Heartbeating -# ------------ -# -# Controller ( time = 2.717828 ) -# ------------------ -# | | | | -# +---+ +---+ +---+ +---+ -# | 0 | | 0 | | 0 | | 0 | -# +---+ +---+ +---+ +---+ -# | -# IDENTITY: foo -# get message: time = 2.717828 -# reply with [ foo, 2.71828 ] -# -# Controller ( foo.status = OK ) -# ------------------ -# | | | | -# +---+ +---+ +---+ +---+ -# | 1 | | 0 | | 0 | | 0 | -# +---+ +---+ +---+ +---+ -# | -# Controller tracks this node as good -# for this heartbeat - -# Shutdown -# -------- -# -# Controller ( state = RUNNING ) -# ------------------ -# | | | | -# +---+ +---+ +---+ +---+ -# | 1 | | 1 | | 1 | | 1 | -# +---+ +---+ +---+ +---+ -# | -# IDENTITY: foo -# send [ DONE ] - -# Controller ( state = SHUTDOWN ) -# Controller topology.remove('foo') -# ------------------ -# | | | -# +---+ +---+ +---+ +---+ -# | | | 1 | | 1 | | 1 | -# +---+ +---+ +---+ +---+ -# | -# IDENTITY: foo -# yield, stop sending messages - -# Termination -# ------------ -# -# Controller ( state = TERMINATE ) -# ------------------ -# | | | | -# +---+ +---+ +---+ +---+ -# | 1 | | 1 | | 1 | | 1 | -# +---+ +---+ +---+ +---+ -# | -# get message PROTOCOL.KILL - -# Controller ( state = TERMINATE ) -# ------------------ -# | | | | -# +---+ +---+ +---+ +---+ -# | 0 | | 0 | | 0 | | 0 | -# +---+ +---+ +---+ +---+ - INIT, SOURCES_READY, RUNNING, TERMINATE = CONTROL_STATES -state_transitions = frozenset([ +CONTROLLER_TRANSITIONS = frozenset([ (-1 , INIT), (INIT , SOURCES_READY), (SOURCES_READY , RUNNING), @@ -233,7 +140,7 @@ class Controller(object): def state(self, new): old, self._state = self._state, new - if (old, new) not in state_transitions: + if (old, new) not in CONTROLLER_TRANSITIONS: raise RuntimeError("Invalid State Transition : %s -> %s" %(old, new)) else: log.error("State Transition : %s -> %s" %(old, new)) @@ -572,6 +479,9 @@ class Controller(object): def shutdown(self, hard=False, soft=True, context=None): + if self.state is CONTROL_STATES.TERMINATE: + return + if not self.polling: return diff --git a/zipline/finance/performance.py b/zipline/finance/performance.py index d0dbb643..c4b08eee 100644 --- a/zipline/finance/performance.py +++ b/zipline/finance/performance.py @@ -287,12 +287,15 @@ class PerformanceTracker(object): if self.results_socket: msg = zp.PERF_FRAME(self.to_dict()) self.results_socket.send(msg) + else: + log.info(self.to_dict()) # if self.trading_environment.max_drawdown: returns = self.todays_performance.returns max_dd = -1 * self.trading_environment.max_drawdown if returns < max_dd: + print 0/0 log.info(str(returns) + " broke through " + str(max_dd)) log.info("Exceeded max drawdown.") # mark the perf period with max loss flag,