Example #1
0
def init_module(module_name, module_is_active):
    if module_is_active:
        # L.l.info("Importing module {}".format(module_name))
        dynclass = my_import(module_name)
        if dynclass:
            # Log.logger.info('Module {} is marked as active'.format(module_name))
            if hasattr(dynclass, 'initialised'):
                inited = dynclass.initialised
            else:
                inited = dynclass.P.initialised
            if not inited:
                L.l.info('Module {} initialising'.format(module_name))
                while True:
                    try:
                        dynclass.init()
                        P.init_mod_list.append(module_name)
                        break
                    except ImportError as iex:
                        traceback.print_exc(file=sys.stdout)
                        if not fix_module(iex):
                            break
                    except Exception as ex:
                        L.l.error("Unable to import the module, er={}".format(ex))
                        break
            else:
                L.l.info('Module {} already initialised, skipping init'.format(module_name))
        else:
            L.l.critical("Module {} failed to load".format(module_name))
    else:
        # L.l.info("Module {} is marked as not active, skipping load".format(module_name))
        '''    if dynclass.initialised:
Example #2
0
def my_import(name):
    # http://stackoverflow.com/questions/547829/how-to-dynamically-load-a-python-class
    while True:
        try:
            mod = __import__(name)
            components = name.split('.')
            for comp in components[1:]:
                mod = getattr(mod, comp)
            return mod
        except ImportError as iex:
            traceback.print_exc(file=sys.stdout)
            if not fix_module(iex):
                break
        except Exception as ex:
            L.l.error("Unable to import module {}, err={}".format(name, ex), exc_info=True)
            return None
Example #3
0
from main.logger_helper import L
from common import fix_module
while True:
    try:
        import prctl
        from pydispatch import dispatcher
        break
    except ImportError as iex:
        if not fix_module(iex):
            break
import threading
import transport.mqtt_io
from pydispatch import dispatcher
from common import utils, Constant
from transport import mqtt_io
__author__ = 'Dan Cristian<*****@*****.**>'


class P:
    initialised = False
    send_json_queue = []
    mqtt_send_lock = threading.Lock()
    send_thread_lock = threading.Lock()
    recv_thread_lock = threading.Lock()
    thread_recv = None
    thread_send = None

    def __init__(self):
        pass