Autodiscover function follows the pattern used by Celery.

    :param packages: List of package names to auto discover modules in.
    :type packages: list of str
    :param related_name_re: Regular expression used to match modules names.
    :type related_name_re: str
    :param ignore_exceptions: Ignore exception when importing modules.
    :type ignore_exceptions: bool

def autodiscover_modules(packages, related_name_re='.+',
                         ignore_exceptions=False):
    """Autodiscover function follows the pattern used by Celery.

    :param packages: List of package names to auto discover modules in.
    :type packages: list of str
    :param related_name_re: Regular expression used to match modules names.
    :type related_name_re: str
    :param ignore_exceptions: Ignore exception when importing modules.
    :type ignore_exceptions: bool
    """
    warnings.warn('autodiscover_modules has been deprecated. '
                  'Use Flask-Registry instead.', DeprecationWarning)
    global _RACE_PROTECTION

    if _RACE_PROTECTION:
        return []
    _RACE_PROTECTION = True
    modules = []
    try:
        tmp = [find_related_modules(pkg, related_name_re, ignore_exceptions)
               for pkg in packages]

        for l in tmp:
            for m in l:
                if m is not None:
                    modules.append(m)
    # Workaround for finally-statement
    except:
        _RACE_PROTECTION = False
        raise
    _RACE_PROTECTION = False
    return modules