How to use the uwsgi.worker_id function in uWSGI

To help you get started, we’ve selected a few uWSGI examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github desec-io / desec-stack / api / api / settings.py View on Github external
# Watchdog
WATCHDOG_SLAVES = os.environ.get('DESECSTACK_WATCHDOG_SLAVES', '').split()
WATCHDOG_WINDOW_SEC = 600

# Prometheus (see https://github.com/korfuri/django-prometheus/blob/master/documentation/exports.md)
#  TODO Switch to PROMETHEUS_METRICS_EXPORT_PORT_RANGE instead of this workaround, which currently necessary to due
#  https://github.com/korfuri/django-prometheus/issues/215
try:
    import uwsgi
except ImportError:
    pass  # not running in uwsgi, e.g. management command
else:
    import prometheus_client
    prometheus_client.values.ValueClass = prometheus_client.values.MultiProcessValue(
        process_identifier=uwsgi.worker_id)

if DEBUG and not EMAIL_HOST:
    EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'

if os.environ.get('DESECSTACK_E2E_TEST', "").upper() == "TRUE":
    DEBUG = True
    LIMIT_USER_DOMAIN_COUNT_DEFAULT = 5000
    USER_ACTIVATION_REQUIRED = False
    EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
    REST_FRAMEWORK['DEFAULT_THROTTLE_CLASSES'] = []
github paradoxxxzero / fawn / little_flask_example.py View on Github external
def index():
    import uwsgi
    message = 'This is a notification from worker %d' % uwsgi.worker_id()
    db.session.execute(fawn.notify('ws', message))
    db.session.commit()

    return """
    
    Page rendered on worker %d <br>
    """ % uwsgi.worker_id()
github unbit / uwsgi / examples / welcome.py View on Github external
def setprocname():
    if uwsgi.worker_id() > 0:
        uwsgi.setprocname("i am the worker %d" % uwsgi.worker_id())
github unbit / uwsgi / hello_world.py View on Github external
def gl_func():
    while True:
        gevent.sleep(2)
        print "i am a greenltet running in worker %d" % uwsgi.worker_id()
github paradoxxxzero / fawn / several_sockets_flask_example.py View on Github external
function handle_socket(i) {
            var s = new WebSocket("ws://" + location.host + "/ws/" + i);
            s.onopen = e =&gt; document.body.innerHTML += i + ' opened  <br>'
            s.onmessage = e =&gt; document.body.innerHTML += e.data + ' (' + i + ') <br>'
            s.onerror = e =&gt; document.body.innerHTML += 'Error (' + i + ')<br>'
            s.onclose = e =&gt; document.body.innerHTML += 'Socket closed (' + i + ')<br>'
            return s;
        }
        document.addEventListener('DOMContentLoaded', function () {
            for (var i = 0; i &lt; 10; i++) {
                sockets.push(handle_socket(i))
            }
        });
    
    Page rendered on worker %d <br>
    """ % uwsgi.worker_id()
github amitsaha / python-prometheus-demo / flask_app_prometheus_worker_id / src / helpers / middleware.py View on Github external
def _get_worker_id():
    if use_uwsgi_worker_id:
        worker_id = uwsgi.worker_id()
    else:
        worker_id = os.getpid()
    return worker_id
github galaxyproject / galaxy / lib / galaxy / tools / toolbox / watcher.py View on Github external
def on_any_event(self, event=None):
        try:
            import uwsgi
            log.warning("Reload event triggered on worker '%s'", uwsgi.worker_id())
        except Exception:
            log.warning("Reload event triggered")
            pass
        self._handle(event)
github webrecorder / pywb / pywb / manager / autoindex.py View on Github external
def run(self):
        try:
            # If running in uwsgi, run AutoIndexer only in first worker!
            import uwsgi
            if uwsgi.worker_id() != 1:
                return
        except:
            pass

        try:
            while self.keep_running:
                self.check_path()
                if not self.interval:
                    break

                time.sleep(self.interval)
        except KeyboardInterrupt:  # pragma: no cover
            return
github paradoxxxzero / fawn / little_flask_example.py View on Github external
def notify(self, payload):
        import uwsgi
        self.send('Notification "%s" received in worker %d in ws %s' % (
            payload, uwsgi.worker_id(), self.rand))