Common logic for nspawn.run functions
770390
def _run(name,
         cmd,
         output=None,
         no_start=False,
         stdin=None,
         python_shell=True,
         preserve_state=False,
         output_loglevel='debug',
         ignore_retcode=False,
         use_vt=False,
         keep_env=None):
    '''
    
    '''
    orig_state = state(name)
    exc = None
    try:
        ret = __salt__['container_resource.run'](
            name,
            cmd,
            container_type=__virtualname__,
            exec_driver=EXEC_DRIVER,
            output=output,
            no_start=no_start,
            stdin=stdin,
            python_shell=python_shell,
            output_loglevel=output_loglevel,
            ignore_retcode=ignore_retcode,
            use_vt=use_vt,
            keep_env=keep_env)
    except Exception:
        raise
    finally:
        # Make sure we stop the container if necessary, even if an exception
        # was raised.
        if preserve_state \
                and orig_state == 'stopped' \
                and state(name) != 'stopped':
            stop(name)

    if output in (None, 'all'):
        return ret
    else:
        return ret[output]
1310598
def run(self, *args, **kwargs) -> Callable:
        
        return self.fn(*args, **kwargs) if args or kwargs else self.fn
244440
def _run_exitfuncs():
    

    while _exithandlers:
        func, targs, kargs =  _exithandlers.pop()
        func(*targs, **kargs)
1073112
function Runnable(title, fn) {
  this.title = title;
  this.fn = fn;
  this.body = (fn || '').toString();
  this.async = fn && fn.length;
  this.sync = !this.async;
  this._timeout = 2000;
  this._slow = 75;
  this._enableTimeouts = true;
  this.timedOut = false;
  this._retries = -1;
  this._currentRetry = 0;
  this.pending = false;
}
284281
function runAsync(context, func, callback)
{
  var result
    , requiresContext = isArrowFunction(func)
    ;

  if (requiresContext)
  {
    result = func.call(null, context, callback);
  }
  else
  {
    result = func.call(context, callback);
  }

  return result;
}
1197784
def _timed_run(self, func, distribution, args=(), kwargs={},  default=None):
        
        class InterruptableThread(threading.Thread):
            def __init__(self):
                threading.Thread.__init__(self)
                self.result = default
                self.exc_info = (None, None, None)

            def run(self):
                try:
                    self.result = func(args, **kwargs)
                except Exception as err:
                    self.exc_info = sys.exc_info()

            def suicide(self):
                raise RuntimeError('Stop has been called')

        it = InterruptableThread()
        it.start()
        started_at = datetime.now()
        it.join(self.timeout)
        ended_at = datetime.now()
        diff = ended_at - started_at

        if it.exc_info[0] is not None:  # if there were any exceptions
            a,b,c = it.exc_info
            raise Exception(a,b,c)  # communicate that to caller

        if it.isAlive():
            it.suicide()
            raise RuntimeError
        else:
            return it.result
1321522
function runningMap(a, fn, init) {
  return a.map(v => init = fn(v, init));
}
650610
function run (N, op, init) {
  var stats = null, value
  for(var j = 0; j < 100; j++) {
    if(init) value = init(j)
    var start = Date.now()
    for(var i = 0; i < N; i++) op(value, i)
    stats = Stats(stats, N/((Date.now() - start)))
  }
  return stats
}
1179593
function setSpawnObject(admin) {
    admin = ((admin === undefined) ? getDefaultAdmin() : admin);
    if (isLinux && admin) {
        spawn = sudoarg;
    } else {
        spawn =  cparg.spawn;
    }
    return admin;
}
390840
function tryCatch(fnc, context, args) {

		try {
			// Start execusting the function
			switch (args.length) {
				// Avoid apply for up to 3 arguments
				case 1:
					fnc.call(context, args[0]);
					break;
				case 2:
					fnc.call(context, args[0], args[1]);
					break;
				case 3:
					fnc.call(context, args[0], args[1], args[2]);
					break;
				case 4:
					fnc.call(context, args[0], args[1], args[2], args[3]);
					break;
				// Use the slower apply
				default:
					fnc.apply(context, args);
			}
		} catch (err) {
			return err;
		}

		return null;
	}
1051275
function runHandler(plugin, handler, cancel) {
  return function runHandlerDelegate(data) {
    if (!data) {
      return Promise.resolve();
    }

    return Promise
      .resolve(handler.handler(data, plugin, cancel))
      .then(function(result) {
        return data.configure(result);
      });
  };
}
296428
function runScriptFile(scriptFile)  {
	//node gets the node arguments, the nscript arguments and the actual script args combined. Slice all node and nscript args away!
	scriptArgs = scriptArgs.slice(scriptArgs.indexOf(scriptFile) + 1);
	if (shell.verbose())
		console.warn("Starting nscript " + scriptFile + scriptArgs.join(" "));

	runNscriptFunction(require(path.resolve(process.cwd(), scriptFile))); //nscript scripts should always export a single function that is the main
}
373370
def run_once(func):
    

    def _inner(*args, **kwargs):
        if func.__name__ in CTX.run_once:
            LOGGER.info('skipping %s', func.__name__)
            return CTX.run_once[func.__name__]

        LOGGER.info('running: %s', func.__name__)
        result = func(*args, **kwargs)
        CTX.run_once[func.__name__] = result
        return result

    return _inner
77509
def run(self, obj):
        
        for d in self.depsuccess:
            if d.status.value != ActionStatus.SUCCESS:
                self.status = ActionStatus(ActionStatus.SKIPPED, "Skipped because action \"%s\" did not succeed." % d.name)
                return
        for d in self.depfail:
            if d.status.value == ActionStatus.SUCCESS:
                self.status = ActionStatus(ActionStatus.SKIPPED, "Skipped because action \"%s\" did not fail." % d.name)
                return
        try:
            self.status = self.actionfunc(obj)
            if not isinstance(self.status, ActionStatus):
                raise TypeError("Expected action function %s to return a ActionStatus" % self.actionfunc)
        except:
            self.status = ActionStatus(ActionStatus.ERROR, "Unexpected Error.", traceback.format_exc())
466346
def _postrun(cls, span, obj, **kwargs):
        
        span.set_tag("response.status_code", obj.status_code)
        span.set_tag(
            "response.content_lenght", len(getattr(obj, 'content', ""))
        )
1311357
@Trivial
    final void accept(boolean runOnSubmitter) {
        long time;
        nsAcceptEnd = time = System.nanoTime();
        if (runOnSubmitter)
            nsQueueEnd = time;
        state.setSubmitted();
    }
674654
function setAlltoNoop (obj, methods) {
    utils.each(methods, function (method) {
        obj[method] = noop
    })
}