Please ensure you're not killing the process before it had started properly
    :param fn:
    :param args:
    :param kwargs:
    :return:
978834
def popen(fn, *args, **kwargs) -> subprocess.Popen:
    

    args = popen_encode(fn, *args, **kwargs)

    logging.getLogger(__name__).debug('Start %s', args)

    p = subprocess.Popen(args)
    return p
414979
def trace(fn): # pragma: no cover
    
    def wrapped(*args, **kwargs):
        msg = []
        msg.append('Enter {}('.format(fn.__name__))

        if args:
            msg.append(', '.join([str(x) for x in args]))

        if kwargs:
            kwargs_str = ', '.join(['{}={}'.format(k, v) for k, v in list(kwargs.items())])
            if args:
                msg.append(', ')
            msg.append(kwargs_str)
        msg.append(')')
        print(''.join(msg))
        ret = fn(*args, **kwargs)
        print('Return {}'.format(ret))
        return ret
    return wrapped
169808
def example(fn):
    ''''''

    @functools.wraps(fn)
    def wrapped():
        try:
            sys.stdout.write('Running: %s\n' % fn.__name__)
            fn()
            sys.stdout.write('\n')
        except KeyboardInterrupt:
            sys.stdout.write('\nSkipping example.\n\n')
            # Sleep a bit to make killing the script easier
            time.sleep(0.2)

    examples.append(wrapped)
    return wrapped
548737
def safe(f):
    

    def wraps(self, *args, **kwargs):
        try:
            return f(self, *args, **kwargs)
        except BadRequest as e:
            return self.response_400(message=str(e))
        except Exception as e:
            logging.exception(e)
            return self.response_500(message=get_error_msg())

    return functools.update_wrapper(wraps, f)
1247830
def mkstemp(*args, **kwargs):
    '''
    
    '''
    if 'prefix' not in kwargs:
        kwargs['prefix'] = '__salt.tmp.'
    close_fd = kwargs.pop('close_fd', True)
    fd_, f_path = tempfile.mkstemp(*args, **kwargs)
    if close_fd is False:
        return fd_, f_path
    os.close(fd_)
    del fd_
    return f_path
58323
def _execute(self, func, command, **new_attributes):
        
        if self._cfg_factory:
            # if we have a cfg_factory
            try:
                # we try to load a config with the factory
                if self.cfg_file:
                    self.cfg = self._cfg_factory(self.cfg_file)
            except Exception as error:
                # raise se exception
                self._cfg_error(error)
        # let's get command(function) argspec
        arg_specs = inspect.getargspec(command)
        if arg_specs.defaults:
            # if we have defaults
            # count defaults arguments
            count = len(arg_specs.defaults)
            # get arguments names
            args_names = arg_specs.args[:count]
            # get keyword arguments names
            kwargs_name = arg_specs.args[count:]
        else:
            # else all names are the args only
            args_names = arg_specs.args
            # and keyword arguments is empty
            kwargs_name = []
        pargs = []
        kwargs = {}
        # for every argument in argument names
        for name in args_names:
            if name == 'args':
                # if argument name is *special name* **args**
                # we append a reference to self.args
                pargs.append(self.args)
            elif name == 'self':
                # else if argment name is *special name* **self**
                if ArgParseInated in inspect.getmro(func.__cls__):
                    # if the class that holds the function is subclass of
                    # ArgParseInated we'll instantiate it, passing some
                    # parameter
                    pargs.append(func.__cls__(self, **new_attributes))
                else:
                    # else we'll instatiate the class without parameters
                    pargs.append(func.__cls__())
            else:
                # else we'll append the argument getting it from the self.args
                pargs.append(getattr(self.args, name))
        # for every argument in keyword arguments
        for name in kwargs_name:
            if name == 'args':
                # if argument name is *special name* **args**
                # we set for the arg a reference to self.args
                kwargs[name] = self.args
            elif name in self.args:
                # else if name is in self.args we'll set the relative value.
                kwargs[name] = getattr(self.args, name)
        # set the **global** write function
        setattr(__builtin__, self._write_name, self.write)
        # set the **global** write line function
        setattr(__builtin__, self._write_line_name, self.writeln)
        # let's setup something.
        for setup_func in self.setup:
            setup_func(self)
        # call event before_execute
        self._self_event('before_execute', command, *pargs, **kwargs)
        # if events returns a non None value we use it as retrval.
        retval, pargs, kwargs = self._call_event(
            'before_execute', command, pargs, kwargs)
        # if before_execute event returns None go on with command
        if retval is None:
            # let's execute the command and assign the returned value to retval
            retval = command(*pargs, **kwargs)
            # call event after_execute
            self._call_event('after_execute', command, pargs, kwargs)
            self._self_event('after_execute', command, *pargs, **kwargs)
        if self.auto_exit:
            # if we have auto_exit is True
            if retval is None:
                self._self_event(
                    'before_exit_ok', command, retval=EXIT_OK, *pargs, **kwargs)
                # if retval is None we'll assume it's EXIT_OK
                self.exit(EXIT_OK)
            elif isinstance(retval, basestring):
                self._self_event('before_exit_ok', command, retval=retval, *pargs, **kwargs)
                # else if retval is a string we will exit with the message and
                # ERRORCODE is equal to 0
                self.exit(EXIT_OK, retval)
            elif isinstance(retval, int):
                if retval == EXIT_OK:
                    self._self_event('before_exit_ok', command, retval=retval, *pargs, **kwargs)
                else:
                    self._self_event('before_exit_error', command, retval=retval, *pargs, **kwargs)
                # else if retval is an integer we'll exits with it as ERRORCODE
                self.exit(retval)
            elif isinstance(retval, (tuple, list,)):
                self._self_event('before_exit_error', command, retval=retval, *pargs, **kwargs)
                # if retval is a tuple or a list we'll exist with ERRORCODE and
                # message
                self.exit(retval[0], retval[1])
            self._self_event('before_exit', command, retval=retval, *pargs, **kwargs)
            self.exit()
        else:
            # else if auto_exit is not True
            # we'll simply return  retval
            return retval
538356
def on_finish(func, handler, args, kwargs):
    
    tracing = handler.settings.get('opentracing_tracing')
    tracing._finish_tracing(handler)

    return func(*args, **kwargs)
1038071
def dont_crash(fn):
    

    def safe_exec(self, *args, **kwargs):
        try:
            return fn(self, *args, **kwargs)
        except Exception as e:
            logging.exception(e)
            QMessageBox.information(
                self, type(e).__name__, " ".join(str(x) for x in e.args)
            )

    return safe_exec
960052
def wait_for(func):
    

    @wraps(func)
    def wrapped(*args, **kwargs):
        timeout = kwargs.pop('timeout', TIMEOUT)

        start = None

        while True:
            try:
                return func(*args, **kwargs)
            except AssertionError:
                # The function took some time to test the assertion, however,
                # the result might correspond to the state of the world at any
                # point in time, perhaps earlier than the timeout. Therefore,
                # start counting time from the first assertion fail, not from
                # before the function was called.
                if not start:
                    start = time()
                if time() - start < timeout:
                    sleep(CHECK_EVERY)
                    continue
                else:
                    raise

    return wrapped
1054430
def validate(self, fn):
        
        if self.duration[1] < 1:
            return
        created = dt.fromtimestamp(os.path.getctime(fn))
        d = {self.duration[0]: self.duration[1]}
        expired = created+timedelta(**d)
        if expired < dt.now():
            log.debug('%s expired, deleted', fn)
            os.remove(fn)
193906
def start(self, *args, **kwargs):
        
        warnings.warn(
            "The 'start()' method is deprecated, please use 'add()' instead", DeprecationWarning
        )
        return self.add(*args, **kwargs)
624176
def safe_output(fn, opts, task, *args, **kwargs):
    
    try:
        return fn(task, *args, **kwargs)
    except Exception as e:
        if opts["skip"] is None or not isinstance(e, opts["skip"]):
            for outp in luigi.task.flatten(task.output()):
                outp.remove()
        raise
860352
def login_required(fn):
    
    @wraps(fn)
    async def wrapped(*args, **kwargs):
        request = args[-1]
        if not isinstance(request, web.BaseRequest):
            msg = ("Incorrect decorator usage. "
                   "Expecting `def handler(request)` "
                   "or `def handler(self, request)`.")
            raise RuntimeError(msg)

        await check_authorized(request)
        return await fn(*args, **kwargs)

    warnings.warn("login_required decorator is deprecated, "
                  "use check_authorized instead",
                  DeprecationWarning)
    return wrapped
404232
def command(f):
    

    @functools.wraps(f)
    def func_wrapper(self, *argv, **kwargs):
        if 'ip' in kwargs:
            ip = kwargs['ip']
            del kwargs['ip']
        else:
            ip = None

        commands = _get_commands(f, self, *argv, **kwargs)
        return self.execute(commands, ip=ip)

    return func_wrapper
871637
def call(self, func, *args, **kwargs):
        
        wrapped = self.wrap(func)
        return wrapped(*args, **kwargs)
1282529
async def ensureKeyPair(self, *args, **kwargs):
        

        return await self._makeApiCall(self.funcinfo["ensureKeyPair"], *args, **kwargs)
1329308
def later(timeout, f, *args, **kwargs):
    '''
    
    '''
    t = Timer(timeout, f, args, kwargs)
    t.start()
    return t