diff --git a/zipline/monitor.py b/zipline/monitor.py index f6b55037..e901b3ab 100644 --- a/zipline/monitor.py +++ b/zipline/monitor.py @@ -163,6 +163,7 @@ class Controller(object): self.ctime = 0 self.tic = time.time() self.freeform = False + self._state = -1 self.associated = [] @@ -218,17 +219,25 @@ class Controller(object): self.topology = frozenset(topology) default_states = [ + CONTROL_STATES.INIT, + CONTROL_STATES.SOURCES_READY, CONTROL_STATES.RUNNING, - CONTROL_STATES.SHUTDOWN, CONTROL_STATES.TERMINATE, ] self.states = states or default_states self.polling = True - - # Start off in RUNNING, state self.state = self.states[0] + @property + def state(self): + return self._state + + @state.setter + def state(self, new): + old, self._state = self._state, new + self.logging.info("[Controller] State Transition : %s -> %s" %(old, new)) + def run(self): self.init_zmq(self.zmq_flavor) @@ -472,7 +481,7 @@ class Controller(object): assert hard or soft, """ Must specify kill hard or soft """ if hard: - self.state = CONTROL_STATES.SHUTDOWN + self.state = CONTROL_STATES.TERMINATE self.logging.info('[Controller] Hard Shutdown') diff --git a/zipline/protocol.py b/zipline/protocol.py index c3291556..90a3184a 100644 --- a/zipline/protocol.py +++ b/zipline/protocol.py @@ -126,9 +126,6 @@ from collections import namedtuple from protocol_utils import Enum, FrameExceptionFactory, namedict from date_utils import EPOCH, UN_EPOCH -#import ujson -#import ultrajson_numpy - # ----------------------- # Control Protocol # ----------------------- @@ -136,9 +133,10 @@ from date_utils import EPOCH, UN_EPOCH INVALID_CONTROL_FRAME = FrameExceptionFactory('CONTROL') CONTROL_STATES = Enum( + 'INIT', + 'SOURCES_READY', 'RUNNING', - 'SHUTDOWN', # a soft kill - 'TERMINATE', # a hard kill + 'TERMINATE', ) CONTROL_PROTOCOL = Enum( @@ -149,6 +147,7 @@ CONTROL_PROTOCOL = Enum( 'OK' , # 3 - rep 'DONE' , # 4 - rep 'EXCEPTION' , # 5 - rep + 'SIGNAL' , # 6 - rep ) def CONTROL_FRAME(event, payload): @@ -174,18 +173,6 @@ def CONTROL_UNFRAME(msg): except ValueError: raise INVALID_CONTROL_FRAME(msg) -# ----------------------- -# Heartbeat Protocol -# ----------------------- - -# These encode the msgpack equivelant of 1 and 2. The heartbeat -# frame should only be 1 byte on the wire. - -HEARTBEAT_PROTOCOL = namedict({ - 'REQ' : b'\x01', - 'REP' : b'\x02', -}) - # ----------------------- # Component State # -----------------------