diff --git a/python_banyan/backplane/backplane.py b/python_banyan/backplane/backplane.py index 7655464..2bb297f 100644 --- a/python_banyan/backplane/backplane.py +++ b/python_banyan/backplane/backplane.py @@ -41,9 +41,13 @@ def __init__(self, subscriber_port='43125', publisher_port='43124', backplane_na """ This is the initializer for the Python Banyan BackPlane class. The class must be instantiated before starting any other Python Banyan components + :param subscriber_port: subscriber IP port number + :param publisher_port: publisher IP port number + :param backplane_name: name to appear on the console for this backplane + :param loop_time: event loop idle timer """ @@ -124,7 +128,21 @@ def bp(): """ Instantiate the backplane and run it. Attach a signal handler for the process to listen for user pressing Control C - :return: + + usage: backplane [-h] [-n BACKPLANE_NAME] [-p PUBLISHER_PORT] [-s SUBSCRIBER_PORT] [-t LOOP_TIME] + + optional arguments: + + -h, --help show this help message and exit + + -n BACKPLANE_NAME Name of this backplane + + -p PUBLISHER_PORT Publisher IP port + + -s SUBSCRIBER_PORT Subscriber IP port + + -t LOOP_TIME Event Loop Timer in seconds + """ parser = argparse.ArgumentParser() diff --git a/python_banyan/banyan_base/banyan_base.py b/python_banyan/banyan_base/banyan_base.py index 148fe44..4413644 100644 --- a/python_banyan/banyan_base/banyan_base.py +++ b/python_banyan/banyan_base/banyan_base.py @@ -55,7 +55,8 @@ class BanyanBase(object): """ def __init__(self, back_plane_ip_address=None, subscriber_port='43125', - publisher_port='43124', process_name='None', loop_time=.1, numpy=False): + publisher_port='43124', process_name='None', loop_time=.1, numpy=False, + external_message_processor=None): """ The __init__ method sets up all the ZeroMQ "plumbing" @@ -74,6 +75,8 @@ def __init__(self, back_plane_ip_address=None, subscriber_port='43125', :param loop_time: Receive loop sleep time. :param numpy: Set true if you wish to include numpy matrices in your messages. + + :param external_message_processor: external method to process messages """ # call to super allows this class to be used in multiple inheritance scenarios when needed @@ -83,6 +86,7 @@ def __init__(self, back_plane_ip_address=None, subscriber_port='43125', self.back_plane_ip_address = None self.numpy = numpy + self.external_message_processor = external_message_processor # if using numpy apply the msgpack_numpy monkey patch if numpy: @@ -96,9 +100,12 @@ def __init__(self, back_plane_ip_address=None, subscriber_port='43125', for pid in psutil.pids(): p = psutil.Process(pid) p_command = p.cmdline() - if any('backplane' in s for s in p_command): - self.backplane_exists = True - else: + try: + if any('backplane' in s for s in p_command): + self.backplane_exists = True + else: + continue + except UnicodeDecodeError: continue if not self.backplane_exists: @@ -114,8 +121,6 @@ def __init__(self, back_plane_ip_address=None, subscriber_port='43125', self.loop_time = loop_time - print() - print('\n************************************************************') print(process_name + ' using Back Plane IP address: ' + self.back_plane_ip_address) print('Subscriber Port = ' + self.subscriber_port) @@ -205,7 +210,10 @@ def incoming_message_processing(self, topic, payload): :param payload: Message Data. """ - print('this method should be overwritten in the child class', topic, payload) + if self.external_message_processor: + self.external_message_processor(topic, payload) + else: + print('this method should be overwritten in the child class', topic, payload) def clean_up(self): """ diff --git a/python_banyan/utils/monitor/monitor.py b/python_banyan/utils/monitor/monitor.py index f971659..f84770c 100644 --- a/python_banyan/utils/monitor/monitor.py +++ b/python_banyan/utils/monitor/monitor.py @@ -42,9 +42,14 @@ def __init__(self, back_plane_ip_address=None, numpy=False): """ This is constructor for the Monitor class + :param back_plane_ip_address: IP address of the currently running backplane + :param subscriber_port: subscriber port number - matches that of backplane + :param publisher_port: publisher port number - matches that of backplane + + :param process_name: default name is "Monitor". Change using this paramenter """ # initialize the base class diff --git a/setup.py b/setup.py index c9a17cd..5df24f2 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='python-banyan', - version='2.2', + version='2.3', packages=[ 'python_banyan', 'python_banyan.banyan_base', @@ -16,7 +16,7 @@ 'u-msgpack-python', 'msgpack-python', 'numpy>=1.9', - 'msgpack-numpy', + 'msgpack-numpy==0.4.1', 'psutil' ],