Exemple #1
0
    def register_model_load_handler(cls, model_path, logger,
                                    within_uwsgi_context):
        logger.info("Model file path: {}".format(model_path))

        if within_uwsgi_context:
            cls._model_selector = ModelSelector(model_path)

            logger.info(
                "Register signal (model reloading): {} (worker, wid: {}, {})".
                format(UwsgiConstants.MODEL_RELOAD_SIGNAL_NUM, cls._wid,
                       UwsgiBroker._model_selector))
            uwsgi.register_signal(UwsgiConstants.MODEL_RELOAD_SIGNAL_NUM,
                                  "workers", cls._model_reload_signal)

            logger.info(
                "Model path to monitor (signal {}, wid: {}): {}".format(
                    UwsgiConstants.MODEL_RELOAD_SIGNAL_NUM, cls._wid,
                    cls._model_selector.model_env.sync_filepath))
            uwsgi.add_file_monitor(UwsgiConstants.MODEL_RELOAD_SIGNAL_NUM,
                                   cls._model_selector.model_env.sync_filepath)
        else:
            if os.path.isfile(model_path):
                UwsgiBroker._restful_comp.load_model_callback(model_path,
                                                              stream=None,
                                                              version=None)
 def __init__(self, path):
     try:
         import os
         import uwsgi
         signal = [signum for signum in range(0,256) if not uwsgi.signal_registered(signum)][0]
         uwsgi.register_signal(signal, '', uwsgi.reload)
         for path in [x[0] for x in os.walk(path)]:
             uwsgi.add_file_monitor(signal, path.decode(encoding='UTF-8'))
     except Exception as err:
         pass # Not running under uwsgi. The other supported alternative is gunicorn. 
Exemple #3
0
 def __call__(self, f):
     uwsgi.register_signal(self.num, self.target, f)
     uwsgi.add_file_monitor(self.num, self.fsobj)
     return f
Exemple #4
0
#app = Flask(__name__)
@rpc('hello')
def hellorpc(foo, bar):
	return "%s-%s-%s" (foo, bar)
def hello():
	return "Hello World"
uwsgi.register_rpc("hello", hello)
def helloapp(env, start_response):
	start_response('200 Ok', [('Content-Type', 'text/html')])
	return uwsgi.rpc('127.0.0.1:3031', 'hello')
def hello_file(num):
	print "/tmp has been modified !!!"
def get(key):
	if key not in domains:
		return DEFAULT_NODE
	# get the node to forward requests to
	nodes = domains[key]['nodes']
	current_node = domains[key]['node']
	value = nodes[current_node]
	# round robin :P
	next_node = current_node + 1
	if next_node >= len(nodes):
		next_node = 0
		domains[key]['node'] = next_node
		return value
#thr root: 
#application = ...
uwsgi.register_signal(17, "worker", hello_file)
uwsgi.add_file_monitor(17, "/tmp")
uwsgi.applications = {'': application, '/app': app, '/helloapp': helloapp}
Exemple #5
0
stack_dump_file = '/tmp/manhole-pid'
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'
Exemple #6
0
try:
    import uwsgi
except ImportError:
    print('Failed to load python module uwsgi')
    # print('Periodic faiss index updates isn\'t enabled')


def hello_file(num):
    print "file has been modified !!!"


uwsgi.register_signal(17, "worker", hello_file)
uwsgi.add_file_monitor(
    17, "/media/chenhao/study/code/mycode/test-faiss/modify.file")
def signal_all_workers_to_run_function_on_file_change(filename, func):
    uwsgi.register_signal(30, 'workers', func)
    uwsgi.add_file_monitor(30, filename)
Exemple #8
0
    def register_ipython_console(self, name):
        trigger = IPYTHON_CONSOLE_TRIGGER % name
        os.close(os.open(trigger, os.O_WRONLY|os.O_CREAT, 0666))

        uwsgi.register_signal(IPYTHON_CONSOLE_SIGNAL, 'mule', activate_ipython_console)
        uwsgi.add_file_monitor(IPYTHON_CONSOLE_SIGNAL, trigger)
Exemple #9
0
    def register_ipython_console(self, name):
        trigger = IPYTHON_CONSOLE_TRIGGER % name
        os.close(os.open(trigger, os.O_WRONLY|os.O_CREAT, 0666))

        uwsgi.register_signal(IPYTHON_CONSOLE_SIGNAL, 'mule', activate_ipython_console)
        uwsgi.add_file_monitor(IPYTHON_CONSOLE_SIGNAL, trigger)
Exemple #10
0
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'