示例#1
0
文件: test_comm.py 项目: safl/levis
    def test_wr(self):

        c = comm.Comm(host=self.server, port=self.port)
        
        c.publish(comm.pack(self.data_struct))        
        c.subscribe(recv_cb)
        
        c.disconnect('network_consumer')
示例#2
0
文件: agent.py 项目: safl/levis
    def output_handler(self):
        """
        Communication, send RPC results and error events.
        """

        while self.running:
            try:
                res = (device_id, task, task_res) = self.output_queue.get(True, 1)  # Grab output from output queue

                method_name   = 'Unknown'
                if 'method' in task:
                    method_name = task['method']

                if 'name' in task:
                    name = task['name']
                else:
                    name = method_name

                invocation_id = None
                if 'id' in task:
                    invocation_id = task['id']
                
                # Check for errors during execution
                (rc, err, out) = (None, None, None)
                try:
                    (rc, err, out) = task_res
                except:
                    logging.debug('OUTPUT-FORMAT-ERROR %s.' % repr(task_res))

                if err:
                    message = comm.pack(comm.rpc_error(rc, err, invocation_id, self.agent_conf['agent_id'], device_id))
                else:
                    message = comm.pack(comm.rpc_response(task_res, invocation_id, self.agent_conf['agent_id'], device_id))

                #publish_tube = "%s-%s" % (self.output_tube, name)
                logging.debug(comm.rpc_response(task_res, invocation_id, self.agent_conf['agent_id'], device_id))
                publish_tube = "%s-%s" % (self.output_tube, method_name)
                logging.debug('Publishing to [%s]...' % publish_tube)
                
                self.publish(message, publish_tube)

            except Queue.Empty:
                pass
            except:
                logging.debug('Noller!', exc_info=3)