Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
uwsgi_signal_number = 17
try:
import uwsgi
if not os.path.exists(stack_dump_file):
open(stack_dump_file, 'w')
def open_manhole(dummy_signum):
with open(stack_dump_file, 'r') as fh:
pid = fh.read().strip()
if pid == str(os.getpid()):
inst = manhole.install(strict=False, thread=False)
inst.handle_oneshot(dummy_signum, dummy_signum)
uwsgi.register_signal(uwsgi_signal_number, 'workers', open_manhole)
uwsgi.add_file_monitor(uwsgi_signal_number, stack_dump_file)
print("Listening for stack mahole requests via %r" % (stack_dump_file,), file=sys.stderr)
except ImportError:
print("Not running under uwsgi; unable to configure manhole trigger", file=sys.stderr)
except IOError:
print("IOError creating manhole trigger %r" % (stack_dump_file,), file=sys.stderr)
def application(env, sr):
sr('200 OK', [('Content-Type', 'text/plain'), ('Content-Length', '2')])
yield b'OK'
def hello_signal2(num, payload):
print "i am the signal %d with payload: %s" % (num, payload)
def hello_file(num, filename):
print "file %s has been modified !!!" % filename
def hello_timer(num, secs):
print "%s seconds elapsed" % secs
# uwsgi.register_signal(30, uwsgi.SIGNAL_KIND_WORKER, hello_signal)
uwsgi.register_signal(30, "workers", hello_signal)
uwsgi.register_signal(22, "worker", hello_signal2, "*** PAYLOAD FOO ***")
uwsgi.register_file_monitor(3, "/tmp", "workers", hello_file)
uwsgi.register_timer(26, 2, "worker", hello_timer)
uwsgi.register_timer(17, 4, "worker2", hello_timer)
uwsgi.register_timer(5, 8, "worker3", hello_timer)
def application(env, start_response):
start_response('200 Ok', [('Content-Type', 'text/html')])
# this will send a signal to the master that will report it to the first available worker
uwsgi.signal(30)
uwsgi.signal(22)
return "signals sent to workers"
def __call__(self, f):
uwsgi.register_signal(self.num, self.target, f)
return f
if elementTime < criticalTime:
print(element)
element.unlink()
def delete_unused_files(signum):
"""Function called by uwsgi periodically
Removes unused files, keeps the disk clean
"""
print("Removing unused files...")
delete_files(AUDIO_DIR)
delete_files(TMP_DIR)
delete_files(SPECS_DIR)
uwsgi.register_signal(1, '', delete_unused_files)
uwsgi.add_timer(1, UPLOADS_DELETION_TIME * 60) # conversion to seconds
@print_execution_time
def generate_spectrograms(audio_filename, time_range, length, offset):
"""Transforms wav file excerpt into a spetrogram.
It simply executes python script inside a shell.
Returns:
A preprocessor script's exit code
"""
command = 'python {script_path} --input {audio_path} --output-dir {spec_dir} --start {start} --end {end} --segment-length {length} --segment-overlap-length {overlap}'.format(
script_path=PROCESSOR_PATH,
audio_path=AUDIO_DIR / audio_filename,
spec_dir=SPECS_DIR,
start=time_range[0],
def __call__(self, f):
uwsgi.register_signal(self.num, self.target, f)
uwsgi.add_file_monitor(self.num, self.fsobj)
return f
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
CARBON_SERVER = "127.0.0.1:2003"
def update_carbon(signum):
# connect to the carbon server
carbon_fd = uwsgi.connect(CARBON_SERVER)
# send data to the carbon server
uwsgi.send(carbon_fd, "uwsgi.%s.requests %d %d\n" % (uwsgi.hostname, uwsgi.total_requests(), int(time.time())))
# close the connection with the carbon server
uwsgi.close(carbon_fd)
# register a new uwsgi signal (signum: 17)
uwsgi.register_signal(17, '', update_carbon)
# attach a timer of 10 seconds to signal 17
uwsgi.add_timer(17, 10)
# the Django app
application = WSGIHandler()
def __call__(self, f):
uwsgi.register_signal(self.num, self.target, f)
uwsgi.add_cron(self.num, self.minute, self.hour,
self.day, self.month, self.dayweek)
return f
def __call__(self, f):
uwsgi.register_signal(self.num, self.target, f)
uwsgi.add_timer(self.num, self.secs)
return f
"""
import os
import uwsgi
from app.blog_lab.proxy.method import get_proxy, check_proxy
from app.blog_lab.proxy.huiyuan import play
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "NewRaPo.settings.produce")
from django.core.wsgi import get_wsgi_applicationß
application = get_wsgi_application()
uwsgi.register_signal(82, "", get_proxy)
uwsgi.add_cron(82, 0, -1, -1, -1, -1)
uwsgi.register_signal(84, "", check_proxy)
uwsgi.add_cron(84, 30, -1, -1, -1, -1)
uwsgi.register_signal(86, "", play)
uwsgi.add_cron(86, 0, 8, -1, -1, -1)
def __call__(self, f):
uwsgi.register_signal(self.num, self.target, f)
uwsgi.add_timer(self.num, self.secs)
return f