def try_instance_init ( self , instance , late_start = False ) : try : instance . init_try += 1 # Maybe it's a retry if not late_start and instance . init_try > 1 : # Do not try until too frequently, or it's too loopy if instance . last_init_try > time . time ( ) - MODULE_INIT_PERIOD : logger . info ( "Too early to retry initialization, retry period is %d seconds" , MODULE_INIT_PERIOD ) # logger.info("%s / %s", instance.last_init_try, time.time()) return False instance . last_init_try = time . time ( ) logger . info ( "Trying to initialize module: %s" , instance . name ) # If it's an external module, create/update Queues() if instance . is_external : instance . create_queues ( self . daemon . sync_manager ) # The module instance init function says if initialization is ok if not instance . init ( ) : logger . warning ( "Module %s initialisation failed." , instance . name ) return False logger . info ( "Module %s is initialized." , instance . name ) except Exception as exp : # pylint: disable=broad-except # pragma: no cover, simple protection msg = "The module instance %s raised an exception " "on initialization: %s, I remove it!" % ( instance . name , str ( exp ) ) self . configuration_errors . append ( msg ) logger . error ( msg ) logger . exception ( exp ) return False return True
how to tell if an init has been called python
Try to initialize the given module instance .
def try_instance_init(self, instance, late_start=False):
        """Try to "initialize" the given module instance.

        :param instance: instance to init
        :type instance: object
        :param late_start: If late_start, don't look for last_init_try
        :type late_start: bool
        :return: True on successful init. False if instance init method raised any Exception.
        :rtype: bool
        """
        try:
            instance.init_try += 1
            # Maybe it's a retry
            if not late_start and instance.init_try > 1:
                # Do not try until too frequently, or it's too loopy
                if instance.last_init_try > time.time() - MODULE_INIT_PERIOD:
                    logger.info("Too early to retry initialization, retry period is %d seconds",
                                MODULE_INIT_PERIOD)
                    # logger.info("%s / %s", instance.last_init_try, time.time())
                    return False
            instance.last_init_try = time.time()

            logger.info("Trying to initialize module: %s", instance.name)

            # If it's an external module, create/update Queues()
            if instance.is_external:
                instance.create_queues(self.daemon.sync_manager)

            # The module instance init function says if initialization is ok
            if not instance.init():
                logger.warning("Module %s initialisation failed.", instance.name)
                return False
            logger.info("Module %s is initialized.", instance.name)
        except Exception as exp:  # pylint: disable=broad-except
            # pragma: no cover, simple protection
            msg = "The module instance %s raised an exception " \
                  "on initialization: %s, I remove it!" % (instance.name, str(exp))
            self.configuration_errors.append(msg)
            logger.error(msg)
            logger.exception(exp)
            return False

        return True