def update_loaded_clients(module_object,class_name): global import_manifest, loaded_clients, init_logger try: class_object = getattr(module_object,class_name) aliases = import_manifest[class_name+"_alias"] updates = dict( [(alias,class_object) for alias in aliases] ) loaded_clients.update(updates) except: init_logger.warning("Unable to load client %s." % class_name) init_logger.info(str(exc))
def try_load(mod_name,class_name): global init_logger try: class_names = iterable(class_name) module_object = do_import(mod_name,class_names) out_names = [] for name in class_names: if hasattr(module_object,name): out_names.append(name) else: init_logger.warning("%s was not found in %s." % (name,mod_name)) return module_object,out_names except ImportError, exc: err1 = "An attempt to load client %s failed. " % class_name err2 = "A dependency of this client may not be installed." err3 = "REASON: %s" % str(exc) #spaces are for output formating. init_logger.warning(err1) init_logger.warning(err2) init_logger.warning(err3) return None,None
from collections import namedtuple from locust.log import init_logger #perhaps warning module is more appropriate but looks ugly, if there #are functional changes as a result this can be reverted. zmq_warn_msg1 = "Using pure Python socket RPC implementation instead of zmq. " zmq_warn_msg2 = "This will not affect you if you're not running locust in distributed mode." zmq_warn_msg3 = "If you are, we recommend you to install: pyzmq and gevent-zeromq" try: import zmqrpc as rpc except ImportError: init_logger.warning(zmq_warn_msg1) init_logger.warning(zmq_warn_msg2) init_logger.warning(zmq_warn_msg3) import socketrpc as rpc Message = namedtuple("Message", ["type", "data", "node_id"])
except ImportError, exc: err1 = "An attempt to load client %s failed. " % class_name err2 = "A dependency of this client may not be installed." err3 = "REASON: %s" % str(exc) #spaces are for output formating. init_logger.warning(err1) init_logger.warning(err2) init_logger.warning(err3) return None,None except Exception,exc: #let users keep working even if some clients can't be loaded. #Assumption is the user is requesting a working client and #shouldn't be prevented from running load tests because there #is a busted client. If this proves to be trouble in practice #simply remove this exception handler and the locust binary #will error out early. init_logger.warning("Unable to load client %s." % class_name) init_logger.info(str(exc)) return None,None def update_loaded_clients(module_object,class_name): global import_manifest, loaded_clients, init_logger try: class_object = getattr(module_object,class_name) aliases = import_manifest[class_name+"_alias"] updates = dict( [(alias,class_object) for alias in aliases] ) loaded_clients.update(updates) except: init_logger.warning("Unable to load client %s." % class_name) init_logger.info(str(exc))