Runs the provided function on startup, passing in an instance of the api
325399
def startup(api=None):
    """"""
    def startup_wrapper(startup_function):
        apply_to_api = hug.API(api) if api else hug.api.from_object(startup_function)
        apply_to_api.add_startup_handler(startup_function)
        return startup_function
    return startup_wrapper
1122101
def init():
    
    loop = asyncio.get_event_loop()
    if loop.is_running():
        raise Exception("You must initialize the Ray async API by calling "
                        "async_api.init() or async_api.as_future(obj) before "
                        "the event loop starts.")
    else:
        asyncio.get_event_loop().run_until_complete(_async_init())
827135
def spawn_api(self, app, decorator=None):
        """"""
        if decorator:
            assert type(decorator).__name__ == 'function'
        self.is_server = True
        self.app = app

        if self.local:
            # Re-generate client callers, this time as local and passing them the app
            self._generate_client_callers(app)

        return spawn_server_api(self.name, app, self.api_spec, self.error_callback, decorator)
160074
def run(self):
        """"""
        if self.init_sec:
            sleep(self.init_sec)
        self._functime = time()
        while self._running:
            start = time()
            self._func()
            self._functime += self.interval_sec
            if self._functime - start > 0:
                sleep(self._functime - start)
1005928
def invoke_in_mainloop(func, *args, **kwargs):
    
    results = queue.Queue()

    @gcall
    def run():
        try:
            data = func(*args, **kwargs)
            results.put(data)
            results.put(None)
        except BaseException:  # XXX: handle
            results.put(None)
            results.put(sys.exc_info())
            raise

    data = results.get()
    exception = results.get()

    if exception is None:
        return data
    else:
        tp, val, tb = results.get()
        raise tp, val, tb
324963
def run_func(func, *args, **kwargs):
    """"""
    ray.init()

    func = ray.remote(func)

    # NOTE: kwargs not allowed for now
    result = ray.get(func.remote(*args))

    # Inspect the stack to get calling example
    caller = inspect.stack()[1][3]
    print("%s: %s" % (caller, str(result)))

    return result
483625
def _start(self):
        """"""
        error = None
        output = None

        try:
            output = self.func(*self.args, **self.kwargs)
        except Exception as err:
            error = err

        if not self._is_finished:
            self.sig_finished.emit(self, output, error)
        self._is_finished = True
87471
def _setup(self):
        ""
        self.example.error = None
        self.example.traceback = ''
        # inject function contexts from parent functions
        c = Context(parent=self.context)
        #for parent in reversed(self.example.parents):
        #    c._update_properties(locals_from_function(parent))
        self.context = c
        if self.is_root_runner:
            run.before_all.execute(self.context)
        self.example.before(self.context)
1356116
def _on_startup(self, *args):
        
        yield from Controller.instance().start()
        # Because with a large image collection
        # without md5sum already computed we start the
        # computing with server start
        asyncio.async(Qemu.instance().list_images())
505613
def entry_point(__func: Callable) -> Callable:
    
    if __func.__module__ == '__main__':
        import sys
        sys.exit(__func())
    else:
        return __func
1253831
def initiate(self, **kwargs):
        ''''''
        run_startup = kwargs.pop('run_startup', True)

        setter = lambda value, name: setattr(self, name, value)

        d = defer.Deferred()
        d.addCallback(defer.drop_param,
                      self.agency._messaging.get_connection, self)
        d.addCallback(setter, "_messaging")
        d.addCallback(defer.drop_param,
                      self.agency._database.get_connection)
        d.addCallback(setter, '_database')
        d.addCallback(defer.drop_param,
                      self._reload_descriptor)
        d.addCallback(defer.drop_param,
                      self._subscribe_for_descriptor_changes)
        d.addCallback(defer.drop_param, self._store_instance_id)
        d.addCallback(defer.drop_param, self._load_configuration)
        d.addCallback(setter, '_configuration')
        d.addCallback(defer.drop_param,
                      self.join_shard, self._descriptor.shard)
        d.addCallback(defer.drop_param,
                      self.journal_agent_created)
        d.addCallback(defer.drop_param,
                      self._call_initiate, **kwargs)
        d.addCallback(defer.drop_param, self.call_next, self._call_startup,
                      call_startup=run_startup)
        d.addCallback(defer.override_result, self)
        d.addErrback(self._startup_error)

        # Ensure the execution chain is broken
        self.call_next(d.callback, None)

        return d
489977
def wrap_threading_start(start_func):
    

    def call(self):
        self._opencensus_context = (
            execution_context.get_opencensus_full_context()
        )
        return start_func(self)

    return call
833309
def spawn_thread(func, *args, **kwargs):
    """"""
    thread = threading.Thread(target=func, args=args, kwargs=kwargs)
    thread.daemon = True
    thread.start()
    return thread
271515
function start() {
    proc = spawn(procCommand, procArgs, procOptions);

    var onClose = function (code) {
      if (!restarting) {
        process.exit(code);
      }
      start();
      restarting = false;
    };

    proc.on('error', function () {
      debug('restarting due error');
      restarting = true;
      proc.kill('SIGINT');
    });

    proc.on('close', onClose);
  }
132598
def _spawn(func, *args, **kwargs):
    
    thr = Thread(target=func, args=args, kwargs=kwargs)
    thr.daemon = True
    thr.start()
    return thr
1121426
def spawn(func, kwargs):
    """"""
    t = threading.Thread(target=func, kwargs=kwargs)
    t.start()
    yield
    t.join()
36614
def run_task(func):
    

    def _wrapped(*a, **k):
        gen = func(*a, **k)
        return _consume_task(gen)

    return _wrapped