Esempio n. 1
0
def env(key, default="", type=None):
    "Extract an environment variable for use in configuration"

    key = "STRUT_" + key

    # First check an internal cache, so we can `pop` multiple times
    # without actually losing the value.
    try:
        rv = env._cache[key]
    except KeyError:
        # We don't want/can't pop off env variables when
        # uwsgi is in autoreload mode, otherwise it'll have an empty
        # env on reload
        if uwsgi_options.get("py-autoreload") == b"1":
            fn = os.environ.__getitem__
        else:
            fn = os.environ.pop

        try:
            rv = fn(key)
            env._cache[key] = rv
        except KeyError:
            rv = default

    if type is None:
        type = types.convert_type(_type(default))

    return type(rv)
Esempio n. 2
0
def check_threads():
    try:
        from uwsgi import opt
    except ImportError:
        return

    if str(opt.get('enable-threads', '0')).lower() in ('false', 'off', 'no', '0'):
        from warnings import warn
        warn(Warning('We detected the use of uwsgi with disabled threads.  '
                     'This will cause issues with the transport you are '
                     'trying to use.  Please enable threading for uwsgi.  '
                     '(Enable the "enable-threads" flag).'))
Esempio n. 3
0
def check_threads():
    try:
        from uwsgi import opt
    except ImportError:
        return

    if str(opt.get('enable-threads',
                   '0')).lower() in ('false', 'off', 'no', '0'):
        from warnings import warn
        warn(
            Warning('We detected the use of uwsgi with disabled threads.  '
                    'This will cause issues with the transport you are '
                    'trying to use.  Please enable threading for uwsgi.  '
                    '(Enable the "enable-threads" flag).'))
Esempio n. 4
0
def check_thread_support():
    try:
        from uwsgi import opt
    except ImportError:
        return

    # When `threads` is passed in as a uwsgi option,
    # `enable-threads` is implied on.
    if "threads" in opt:
        return

    if str(opt.get("enable-threads",
                   "0")).lower() in ("false", "off", "no", "0"):
        from warnings import warn

        warn(
            Warning("We detected the use of uwsgi with disabled threads.  "
                    "This will cause issues with the transport you are "
                    "trying to use.  Please enable threading for uwsgi.  "
                    '(Enable the "enable-threads" flag).'))
Esempio n. 5
0
import warnings

running_uwsgi = False
threads_enabled = False

# From docs (https://uwsgi-docs.readthedocs.io/en/latest/PythonModule.html):
# > The uWSGI server automagically adds a uwsgi module into your Python
#   apps.
# > This is useful for configuring the uWSGI server, use its internal
#   functions and get statistics. Also useful for detecting whether you're
#   actually running under uWSGI; if you attempt to import uwsgi and
#   receive an ImportError you're not running under uWSGI.
try:
    # > uwsgi.opt
    # > The current configuration options, including any custom placeholders.
    from uwsgi import opt
    running_uwsgi = True
    threads_enabled = opt.get('enable-threads', False)
except ImportError:
    pass

__all__ = ('warn_if_running_uwsgi_without_threads', )


def warn_if_running_uwsgi_without_threads():
    if running_uwsgi and not threads_enabled:
        warnings.warn(('Bugsnag cannot run asynchronously under uWSGI' +
                       ' without enabling thread support. Please run uwsgi' +
                       ' with --enable-threads'), RuntimeWarning)