当前位置: 首页>>代码示例>>Python>>正文


Python exception_formatter.ExceptionFormatter类代码示例

本文整理汇总了Python中afqueue.common.exception_formatter.ExceptionFormatter的典型用法代码示例。如果您正苦于以下问题:Python ExceptionFormatter类的具体用法?Python ExceptionFormatter怎么用?Python ExceptionFormatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ExceptionFormatter类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_command

def run_command(message, reply_message_type):
    
    try:
        
        # Create the ZMQ context.
        zmq_context = zmq.Context(1)
        
        # Form return dictionary.
        results_dict = dict()
        
        # Issue the command to each IP/Port combination we were given.
        for address in parsed_arguments.address.split(","):
            
            # Split the IP and port.
            split_data = address.split(":")
            bridge_ip = split_data[0]
            bridge_port = split_data[1]
        
            # Get the connection string and create the socket connection. 
            connection_string = ZmqUtilities.get_socket_connection_string(bridge_ip, bridge_port)
            remote_request_socket = zmq_context.socket(zmq.REQ)
            remote_request_socket.setsockopt(zmq.LINGER, 0)
            remote_request_socket.connect(connection_string)
            
            try:    
                
                # Send and wait for a reply.
                print("Sending message: {0}".format(message))
                message.send(remote_request_socket)
                
                # Get the message; initialize to not handled.
                print("Waiting for reply...")
                raw_message = SocketWrapper.pull_message(remote_request_socket)
                                
                # Path off command.
                reply_message = reply_message_type.create_from_received(raw_message)
                if int(reply_message.response_code) >= 500:
                    raise Exception("Error code returned.  Reply: {0}".format(reply_message))
                
                #
                results_dict[address] = reply_message
                        
            except:
                
                raise ExceptionFormatter.get_full_exception()
            
            finally:
                    
                # Destroy our socket.
                remote_request_socket.setsockopt(zmq.LINGER, 0)
                remote_request_socket.close()
                
        # Return results.
        return results_dict

    except:
        
        raise ExceptionFormatter.get_full_exception()
开发者ID:appfirst,项目名称:distributed_queue_manager,代码行数:58,代码来源:bridge_commander.py

示例2: _handle_system_bridge_worker_timed_out

 def _handle_system_bridge_worker_timed_out(self, message):
     """
     """
     
     try:
         
         # Log.
         self.logger.log_error("Received bridge worker timed out: {0}.  Stopping and removing bridge worker thread from tracking.".format(message.thread_name))
         
         # Kill.
         bridge_worker = self._bridge_worker_manager.stop_and_remove_bridge_worker_by_thread_name(message.thread_name)
         
         # If no bridge worker was returned, denote.
         if bridge_worker == None:
             self.logger.log_error("No bridge worker found for given thread name: {0}.".format(message.thread_name))
         
         # If a thread worker was found, handle the removed bridge worker due to the time out.
         else:
             
             # Register the bridge worker's connection string in our recreation tracker.
             if bridge_worker.connection_string not in list(self._worker_recreation_tracker_dict.keys()):
                 self._worker_recreation_tracker_dict[bridge_worker.connection_string] = 0
                 self._worker_recreation_time_stamp_dict[bridge_worker.connection_string] = list()
             self._worker_recreation_tracker_dict[bridge_worker.connection_string] = self._worker_recreation_tracker_dict[bridge_worker.connection_string] + 1 
             
         # Return that we successfully handled the message.
         return True
     
     except:
         
         raise ExceptionFormatter.get_full_exception()     
开发者ID:appfirst,项目名称:distributed_queue_manager,代码行数:31,代码来源:network_bridge.py

示例3: query_remote_shared_memory

 def query_remote_shared_memory(self, pqm_id_string, query_method, *arguments):
     """
     Directs the shared memory object to query the remote shared memory of the given PQM.
     Supply the method to run against the remote shared memory and the arguments required to normally make that call.
     Note you will need the full method signature.  For example:
         If you call with shared_memory_manager.query_remote_shared_memory, supply shared_memory_manager.<method_name>.
     Note: If a connection information can't be found, a RedisConnectionUnknownException will be raised.  Be sure to check for this and handle as desired!
     Note: If a connection can't be made to remote shared memory, a RedisConnectionFailureException will be raised.  Be sure to check for this and handle as desired!
     """
     
     # Get the remote client; raise an unknown exception if we have no data mapped for the PQM ID String.
     remote_redis_client = self._pqm_redis_client_dict.get(pqm_id_string, None)
     if remote_redis_client == None:
         raise RedisConnectionUnknownException(pqm_id_string)
         
     # Temporarily overwrite our client and run the command.
     qm_redis_client = self._qm_redis_client
     self._qm_redis_client = remote_redis_client
     
     # Ensure we don't permanently set our main redis client to the remote redis client by trapping
     try:
         
         # Run the query, reset our redis client, and return the result.
         result = query_method(*arguments)
         self._qm_redis_client = qm_redis_client
         return result
     
     except:
         
         # If we hit an exception, reset our redis client, and raise a connection failure exception.
         self._qm_redis_client = qm_redis_client
         #del(self._pqm_redis_client_dict[pqm_id_string])
         raise RedisConnectionFailureException(ExceptionFormatter.get_message())
开发者ID:appfirst,项目名称:distributed_queue_manager,代码行数:33,代码来源:shared_memory_manager.py

示例4: create_and_add_worker

    def create_and_add_worker(self, connection_string):
        
        try:
            
            # Get the next thread index; update the tracker.
            thread_index = self._connection_string_last_thread_index_map.get(connection_string, 0) + 1
            self._connection_string_last_thread_index_map[connection_string] = thread_index
            
            # Get the thread name.
            thread_name = connection_string + "_" + str(thread_index)
            
            # Create the process.
            notification_queue = Queue()
            data_worker_process = Process(target=bridge_worker_thread, 
                                             args=(thread_name, 
                                                   self._zmq_context, 
                                                   self._worker_router_socket_port,
                                                   connection_string, self.config.bridge_worker_remote_poll_timeout,
                                                   notification_queue, self._child_thread_notification_queue,),
                                             name=thread_name)
            
            # Create the bridge worker; update the tracker.
            bridge_worker = BridgeWorker(thread_name, connection_string, data_worker_process, notification_queue)
            self._connection_string_workers_map.setdefault(connection_string, list()).append(bridge_worker)
            
            # Register in our master thread list.
            self._master_thread_name_list.append(thread_name)
            
            # Return the worker.
            return bridge_worker
        
        except:

            raise ExceptionFormatter.get_full_exception()
开发者ID:appfirst,项目名称:distributed_queue_manager,代码行数:34,代码来源:bridge_worker_manager.py

示例5: _handle_command_remote_connect_request

 def _handle_command_remote_connect_request(self, message):
     """
     Returns True/False depending on if the message was handled or not.
     """
     
     try:
         
         # Notify.
         notification_string = "Command received: Remote connect.  IP: {0}; Port: {1}; Count: {2}".format(message.remote_ip_address, message.remote_port, message.count)
         self.logger.log_info(notification_string)
     
         # Get the connection string and create and register a new bridge worker.
         connection_string = ZmqUtilities.get_socket_connection_string(message.remote_ip_address, message.remote_port)
         
         # Create <count> new bridge workers with the connection string.
         for _ in range(message.count):
             
             # Create and add a new worker with the connection info. 
             bridge_worker = self._bridge_worker_manager.create_and_add_worker(connection_string)
             bridge_worker.process.start()
         
         # Return success.
         return True
     
     except:
         
         raise ExceptionFormatter.get_full_exception()                   
开发者ID:appfirst,项目名称:distributed_queue_manager,代码行数:27,代码来源:network_bridge.py

示例6: stop_and_remove_bridge_workers_by_connection_string

 def stop_and_remove_bridge_workers_by_connection_string(self, connection_string, count):
             
     try:
         
         # For each count given.
         for _ in range(count):
             
             # Get the remaining workers; if we have none left, return out.
             bridge_worker_list = self._connection_string_workers_map.get(connection_string, list())
             if len(bridge_worker_list) == 0:
                 return
             
             # Get the bridge worker.
             bridge_worker = bridge_worker_list[0]
             
             # Shut down the bridge worker.                        
             bridge_worker.should_shutdown = True
             bridge_worker.action_queue.put(system_messages.SystemStopThreadMessage(), False)
             bridge_worker.process.join()
             
             # Remove the bridge worker from our list.
             self._connection_string_workers_map[connection_string].remove(bridge_worker)
     
     except:
         
         raise ExceptionFormatter.get_full_exception()    
开发者ID:appfirst,项目名称:distributed_queue_manager,代码行数:26,代码来源:bridge_worker_manager.py

示例7: send

 def send(self, socket):
     """
     Sends the message over the socket.
     """
     
     try:
         if self.master_setup_data_message != None:
             master_setup_data_message = self.master_setup_data_message.dump()
         else:
             master_setup_data_message = ""
             
         if self.master_control_data_message != None:
             master_control_data_message = self.master_control_data_message.dump()
         else:
             master_control_data_message = ""
             
             
         BaseMessage._send_with_destination_and_delimiter(self, socket, self.reply_id_tag, 
                                                          bson.dumps(self.settings_dict), 
                                                          self.sender_dealer_id_tag,  
                                                          str(self.sender_master_flag),
                                                          master_setup_data_message, master_control_data_message,
                                                          str(self.master_synchronization_failure_flag),  
                                                          str(self.ping_back_success_flag))
     except:
         raise ExceptionFormatter.get_full_exception()
开发者ID:appfirst,项目名称:distributed_queue_manager,代码行数:26,代码来源:peer_messages.py

示例8: stop_and_remove_bridge_worker_by_thread_name

 def stop_and_remove_bridge_worker_by_thread_name(self, thread_name):
     """
     Finds the bridge worker with the given thread name.
     Denotes the worker should shut down, ensures it is stopped/stopping via a stop thread command, joins the thread, and removes the worker from tracking.
     Returns the worker object.
     """
     
     try:
         
         # Go through all bridge workers to find the worker with the matching thread name.
         for bridge_worker_list in list(self._connection_string_workers_map.values()):
             for bridge_worker in bridge_worker_list:
                 if bridge_worker.thread_name == thread_name:                        
                     bridge_worker.should_shutdown = True
                     bridge_worker.action_queue.put(system_messages.SystemStopThreadMessage(), False)
                     bridge_worker.process.join()
                     bridge_worker_list.remove(bridge_worker)
                     return bridge_worker
                 
         # If we didn't return from the above loop, we did not find a matching worker to the thread name given.
         return None#raise Exception("Bridge worker does not exist: {0}".format(thread_name))
     
     except:
         
         raise ExceptionFormatter.get_full_exception()     
开发者ID:appfirst,项目名称:distributed_queue_manager,代码行数:25,代码来源:bridge_worker_manager.py

示例9: send

 def send(self, socket):
     """
     Sends the message over the socket.
     """
     try:
         BaseMessage._send(self, socket, self.queue_name, self.routing_key, bson.dumps({self.routing_key: self.data}))        
     except: 
         raise ExceptionFormatter.get_full_exception()
开发者ID:appfirst,项目名称:distributed_queue_manager,代码行数:8,代码来源:client_messages.py

示例10: create_from_received

 def create_from_received(raw_message):
     """
     Returns a new message of this type from the raw message data.
     """
     
     try:
         return ClientUnlockQueuesReplyMessage(None, json.loads(raw_message[1]), raw_message[2])
     except:
         raise ReplyTranslationException(ExceptionFormatter.get_message())
开发者ID:appfirst,项目名称:distributed_queue_manager,代码行数:9,代码来源:client_messages.py

示例11: create_from_received

 def create_from_received(raw_message, sender_id_string):
     """
     Returns a new message of this type from the raw message data.
     """
     
     try:
         return PeerRequestMasterDataMessage(None, sender_id_string)
     except:
         raise ExceptionFormatter.get_full_exception()
开发者ID:appfirst,项目名称:distributed_queue_manager,代码行数:9,代码来源:peer_messages.py


注:本文中的afqueue.common.exception_formatter.ExceptionFormatter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。