Partial original request func and run it in a thread.
437508
def request(self, *args, **kwargs):
        
        func = partial(super().request, *args, **kwargs)
        return self.loop.run_in_executor(self.thread_pool, func)
651398
private void handleRequest(long requestId, Object request, HandlerHolder handler) {
    @SuppressWarnings("unchecked")
    CompletableFuture<Object> responseFuture = handler.handler.apply(request);
    if (responseFuture != null) {
      responseFuture.whenComplete((response, error) -> {
        ThreadContext context = ThreadContext.currentContext();
        if (context == null) {
          this.context.executor().execute(() -> {
            if (error == null) {
              handleRequestSuccess(requestId, response, this.context);
            } else {
              handleRequestFailure(requestId, error, this.context);
            }
          });
        } else {
          if (error == null) {
            handleRequestSuccess(requestId, response, context);
          } else {
            handleRequestFailure(requestId, error, context);
          }
        }
      });
    }
  }
803340
def argument_request_user(obj, func_name):
    """"""
    func = getattr(obj, func_name)
    request = threadlocals.request()
    if request:
        return func(request.user)
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
987016
def threadpooled(
    func: typing.Callable[..., typing.Union["typing.Awaitable[typing.Any]", typing.Any]],
    *,
    loop_getter: None = None,
    loop_getter_need_context: bool = False,
) -> typing.Callable[..., "concurrent.futures.Future[typing.Any]"]:
    """"""
860652
def execute(self, fn, *args, **kwargs):
        """"""
        if not self.asynchronous:
            return fn(*args, **kwargs)
        raise NotImplementedError
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
133289
def run(self, func, *func_args, **func__kwargs):
        
        self._func = func
        self._func_args = func_args
        self._func_kwargs = func__kwargs
        return self
635989
def process_request_thread(self, mainthread):
        """"""
        life_time   = time.time()
        nb_requests = 0

        while not mainthread.killed():
            if self.max_life_time > 0:
                if (time.time() - life_time) >= self.max_life_time:
                    mainthread.add_worker(1)
                    return
                try:
                    SocketServer.ThreadingTCPServer.process_request_thread(self, *self.requests.get(True, 0.5))
                except Queue.Empty:
                    continue
            else:
                SocketServer.ThreadingTCPServer.process_request_thread(self, *self.requests.get())

            LOG.debug("nb_requests: %d, max_requests: %d", nb_requests, self.max_requests)
            nb_requests += 1

            if self.max_requests > 0 and nb_requests >= self.max_requests:
                mainthread.add_worker(1)
                return
1157129
def run_locally(self):
        """"""
        self.thread = threading.Thread(target=self.execute_locally)
        self.thread.daemon = True # So that they die when we die
        self.thread.start()
1344814
def send_request(req=None, method=None, requires_response=True):
    """"""
    if req is None:
        return functools.partial(send_request, method=method,
                                 requires_response=requires_response)

    @functools.wraps(req)
    def wrapper(self, *args, **kwargs):
        params = req(self, *args, **kwargs)
        _id = self.send(method, params, requires_response)
        return _id
    wrapper._sends = method
    return wrapper
1311356
def call_sync(func):
    """"""

    @wraps(func)
    def wrapper(self, *args, **kw):
        """Wraps instance method to be called on loop thread"""

        # Just return when already on the event thread
        if self.thread.ident == get_ident():
            return func(self, *args, **kw)

        barrier = Barrier(2)
        result = None
        ex = None

        def call():
            """Calls function on loop thread"""
            nonlocal result, ex
            try:
                result = func(self, *args, **kw)
            except Exception as exc:
                ex = exc
            finally:
                barrier.wait()

        self.loop.call_soon_threadsafe(call)
        barrier.wait()
        if ex:
            raise ex or Exception("Unknown error")
        return result

    return wrapper
55193
def run(self):
        """"""
        ret = eventlet.spawn(self.context(self.func))
        eventlet.sleep(self.seconds)
        try:
            ret.wait()
        except Exception:  # pylint: disable=broad-except
            traceback.print_exc()
        self.thread = eventlet.spawn(self.run)
1130389
def run(self):
        

        try:
            self.__options.callbacks.request_in_thread_before_start(self.__queue_item)
        except Exception as e:
            print(e)

        new_requests = []
        failed = False

        try:
            handler = Handler(self.__options, self.__queue_item)
            new_requests = handler.get_new_requests()

            try:
                self.__queue_item.response.raise_for_status()
            except Exception:
                if self.__queue_item.request.parent_raised_error:
                    failed = True
                else:
                    for new_request in new_requests:
                        new_request.parent_raised_error = True

        except Exception as e:
            failed = True

            error_message = "Setting status of '{}' to '{}' because of an HTTP error.".format(
                self.__queue_item.request.url,
                QueueItem.STATUS_ERRORED
            )

            DebugHelper.output(self.__options, error_message)
            DebugHelper.output(self.__options, e)

            try:
                self.__options.callbacks.request_on_error(self.__queue_item, str(e))
            except Exception as e:
                print(e)

        for new_request in new_requests:
            new_request.parent_url = self.__queue_item.request.url

        try:
            self.__options.callbacks.request_in_thread_after_finish(self.__queue_item)
        except Exception as e:
            print(e)

        with self.__callback_lock:
            self.__callback(self.__queue_item, new_requests, failed)
1121426
def spawn(func, kwargs):
    """"""
    t = threading.Thread(target=func, kwargs=kwargs)
    t.start()
    yield
    t.join()
335172
def execute(self, requests, resp_generator, *args, **kwargs):
        '''
            
        '''
        return [resp_generator(request) for request in requests]
833309
def spawn_thread(func, *args, **kwargs):
    """"""
    thread = threading.Thread(target=func, args=args, kwargs=kwargs)
    thread.daemon = True
    thread.start()
    return thread