Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# 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'] = []
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()
def setprocname():
if uwsgi.worker_id() > 0:
uwsgi.setprocname("i am the worker %d" % uwsgi.worker_id())
def gl_func():
while True:
gevent.sleep(2)
print "i am a greenltet running in worker %d" % uwsgi.worker_id()
function handle_socket(i) {
var s = new WebSocket("ws://" + location.host + "/ws/" + i);
s.onopen = e => document.body.innerHTML += i + ' opened <br>'
s.onmessage = e => document.body.innerHTML += e.data + ' (' + i + ') <br>'
s.onerror = e => document.body.innerHTML += 'Error (' + i + ')<br>'
s.onclose = e => document.body.innerHTML += 'Socket closed (' + i + ')<br>'
return s;
}
document.addEventListener('DOMContentLoaded', function () {
for (var i = 0; i < 10; i++) {
sockets.push(handle_socket(i))
}
});
Page rendered on worker %d <br>
""" % uwsgi.worker_id()
def _get_worker_id():
if use_uwsgi_worker_id:
worker_id = uwsgi.worker_id()
else:
worker_id = os.getpid()
return worker_id
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)
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
def notify(self, payload):
import uwsgi
self.send('Notification "%s" received in worker %d in ws %s' % (
payload, uwsgi.worker_id(), self.rand))