From e38b9470048821f8831366579170f8b3af2b87be Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Tue, 28 Feb 2012 22:59:31 -0500 Subject: [PATCH] Zipline integration to qexec. --- zipline/component.py | 47 +++++++++++++++++++++++----------- zipline/monitor.py | 7 ++--- zipline/test/client.py | 15 +++++++---- zipline/test/test_messaging.py | 3 ++- 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/zipline/component.py b/zipline/component.py index d5ddc37f..354118f1 100644 --- a/zipline/component.py +++ b/zipline/component.py @@ -141,15 +141,13 @@ class Component(object): self.setup_control() self.loop() - self.shutdown() - self.teardown_sockets() self.end_tick = time.clock() # shouldn't block if we've done our job correctly # self.context.term() - def run(self, catch_exceptions=False): + def run(self, catch_exceptions=True): """ Run the component. @@ -170,15 +168,21 @@ class Component(object): self.signal_exception(exc) fail = exc finally: - # TODO: cleaner + + self.shutdown() + self.teardown_sockets() + if self.context: self.context.destroy() if fail: raise fail else: - self._run() - if(self.context != None): - self.context.destroy() + try: + self._run() + finally: + self.shutdown() + self.teardown_sockets() + def loop(self): """ @@ -383,6 +387,18 @@ class Component(object): # Description and Debug # --------------------- + def extern_logger(self): + """ + Pipe logs out to a provided logging interface. + """ + pass + + def setup_extern_logger(self): + """ + Pipe logs out to a provided logging interface. + """ + pass + @property def get_id(self): """ @@ -416,14 +432,15 @@ class Component(object): """ Debug information about the component. """ - return ( - self.get_id , - self.huid , - socket.gethostname() , - os.getpid() , - hex(id(self)) , - self.sockets , - ) + return { + 'id' : self.get_id , + 'huid' : self.huid , + 'host' : socket.gethostname() , + 'pid' : os.getpid() , + 'memaddress' : hex(id(self)) , + 'ready' : self.successful() , + 'succesfull' : self.ready() , + } def __len__(self): """ diff --git a/zipline/monitor.py b/zipline/monitor.py index 2c869a03..7f6cab2d 100644 --- a/zipline/monitor.py +++ b/zipline/monitor.py @@ -114,7 +114,6 @@ class Controller(object): while self.polling: try: msg = self.pull.recv() - print msg self.pub.send(msg) except KeyboardInterrupt: self.polling = False @@ -171,6 +170,8 @@ class Controller(object): if not context: context = zmq.Context() + #logging.info('Shutdown controller') + s = self.message_sender(context) s.send(CONTROL_FRAME( 'controller', @@ -186,8 +187,8 @@ class Controller(object): """ self.shutdown() - def __del__(self): - self.shutdown() + #def __del__(self): + #self.shutdown() def qos(self): if not self.debug: diff --git a/zipline/test/client.py b/zipline/test/client.py index 35db6943..227bdea1 100644 --- a/zipline/test/client.py +++ b/zipline/test/client.py @@ -1,14 +1,18 @@ +#import logging import ujson as json import zipline.util as qutil import zipline.messaging as qmsg from zipline.protocol import CONTROL_PROTOCOL, COMPONENT_TYPE +#qlogger = logging.getLogger('qexec') + class TestClient(qmsg.Component): def __init__(self, utest, expected_msg_count=0): qmsg.Component.__init__(self) + # Generally shouldn't reference unit tests here. self.utest = utest self.expected_msg_count = expected_msg_count @@ -37,15 +41,16 @@ class TestClient(qmsg.Component): if self.data_feed in socks and socks[self.data_feed] == self.zmq.POLLIN: msg = self.data_feed.recv() + #logger.info('msg:' + str(msg)) if msg == str(CONTROL_PROTOCOL.DONE): qutil.LOGGER.info("Client is DONE!") self.signal_done() - self.utest.assertEqual( - self.expected_msg_count, self.received_count, - "The client should have received ({n}) the same number of \ - messages as the feed sent ({m})." - .format(n=self.received_count, m=self.expected_msg_count)) + #self.utest.assertEqual( + #self.expected_msg_count, self.received_count, + #"The client should have received ({n}) the same number of \ + #messages as the feed sent ({m})." + #.format(n=self.received_count, m=self.expected_msg_count)) return self.received_count += 1 diff --git a/zipline/test/test_messaging.py b/zipline/test/test_messaging.py index 9aeb1653..b7027805 100644 --- a/zipline/test/test_messaging.py +++ b/zipline/test/test_messaging.py @@ -107,7 +107,8 @@ class SimulatorTestCase(object): # Simulation # ---------- - sim.simulate() + sim_context = sim.simulate() + sim_context.join() # Stop Running # ------------