Threading callback
339494
def run(self):
        """"""

        self.viewing = True
        while self.viewing and self._lock.acquire():
            try:
                line = self._readline()
            except:
                pass
            else:
                logger.info(line)
            self._lock.release()
            time.sleep(0)
957938
def defer(callable):
    '''
    '''
    t = threading.Thread(target=callable)
    t.start()
    return t.join
158488
def threadsafe_call(self, fn, *args, **kwargs):
        """"""
        def handler():
            try:
                fn(*args, **kwargs)
            except Exception:
                warn("error caught while excecuting async callback\n%s\n",
                     format_exc())

        def greenlet_wrapper():
            gr = greenlet.greenlet(handler)
            gr.switch()

        self._async_session.threadsafe_call(greenlet_wrapper)
721584
def _threaded(self, *args, **kwargs):
        """"""

        for target in self.targets:
            result = target(*args, **kwargs)
            self.queue.put(result)
1306232
def _enable_thread_pool(func):
    

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        self = args[0]
        if self.enable_thread_pool and hasattr(self, 'thread_pool'):
            future = self.thread_pool.submit(func, *args, **kwargs)
            is_async = kwargs.get('is_async')
            if is_async is None or not is_async:
                timeout = kwargs.get('timeout')
                if timeout is None:
                    timeout = 2
                try:
                    result = future.result(timeout=timeout)
                except TimeoutError as e:
                    self.logger.exception(e)
                    result = None
                return result
            return future
        else:
            return func(*args, **kwargs)

    return wrapper
236541
def submit(self, fn, *args, **kwargs):
        """"""
        corofn = asyncio.coroutine(lambda: fn(*args, **kwargs))
        return run_coroutine_threadsafe(corofn(), self.loop)
976564
def _invoke_callbacks(self):
        """"""
        self.task_end_time = time.time()
        self.task_cost_time = self.task_end_time - self.task_start_time
        with self._condition:
            for callback in self._done_callbacks:
                try:
                    result = callback(self)
                    if callback in self._user_callbacks:
                        self._callback_result = result
                except Exception as e:
                    Config.main_logger.error("exception calling callback for %s" % e)
            self._condition.notify_all()
24033
def call_async(func):
    """"""

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

        def call():
            """Calls function on loop thread"""
            try:
                func(self, *args, **kw)
            except Exception:
                logger.exception(
                    "failed to call async [%r] with [%r] [%r]", func, args, kw
                )

        self.loop.call_soon_threadsafe(call)

    return wrapper
1157436
def create_thread(daemon, callback, *callbackParams):
    
    task = Thread(target=callback, args=callbackParams)
    task.setDaemon(daemon)
    return task
785067
protected void threadBegin() {
        //
        // Note the 'beforeCallbacks' list is not going to have a well-defined order, so it is of limited use.
        // We probably want to revisit this with some kind of priority/order based on ranking to make
        // it more useful.
        //
        // At the moment we treat the setting of the tran timeout separately, rather than as a IJobExecutionStartCallbackService,
        // to reflect the fact that this is provided by a required dependency.  If we were to want this to function in SE mode,
        // say, we might want to factor this too as an "extension" that is provided by another layer, and so incorporate this into a
        // more generic, extensible "before" processing.
        try {
            tranMgr.setTransactionTimeout(0);
            if (beforeCallbacks != null) {
                for (IJobExecutionStartCallbackService callback : beforeCallbacks) {
                    if (logger.isLoggable(Level.FINER)) {
                        logger.logp(Level.FINER, CLASSNAME, "threadBegin", "Calling before callback", callback);
                    }
                    callback.jobStarted(runtimeWorkUnitExecution);
                }
            }
        } catch (Throwable t) {
            // Fail the execution if any of our before-work-unit callbacks failed. E.g. the joblog context setup
            // was unsuccessful. We may want to make it an option whether or not to fail here in the future.
            runtimeWorkUnitExecution.logExecutionFailedMessage();
            throw new BatchContainerRuntimeException("An error occurred during thread initialization.", t);
        }
    }
308736
def _execute_callback(self, callback, data):
        """"""
        web_client = WebClient(
            token=self.token, base_url=self.base_url, ssl=self.ssl, proxy=self.proxy
        )
        with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
            # Execute the callback on a separate thread,
            future = executor.submit(
                callback, rtm_client=self, web_client=web_client, data=data
            )

            while future.running():
                pass

            future.result()
866728
def _call_in_reactor_thread(self, f, *args, **kwargs):
        """"""
        self._reactor.callFromThread(f, *args, **kwargs)
1104101
def asyncthread(func):
    ''
    @functools.wraps(func)
    def _execAsync(*args, **kwargs):
        return vd().execAsync(func, *args, **kwargs)
    return _execAsync
372771
def run_callbacks(index = 0, &block)
        if transition = self[index]
          throw :halt unless transition.run_callbacks(:after => !skip_after) do
            run_callbacks(index + 1, &block)
            {:result => results[transition.action], :success => success?}
          end
        else
          persist
          run_actions(&block)
        end
      end
1074316
def connect(cls, *args, **kwargs):
        
        loop = kwargs.get('loop')
        if loop is None:
            loop = trollius.get_event_loop()
        future = trollius.Future(loop=loop)

        def callback(arg):
            if not future.done():
                if isinstance(arg, Exception):
                    loop.call_soon_threadsafe(future.set_exception, arg)
                else:
                    loop.call_soon_threadsafe(future.set_result, arg)

        stream = cls(callback, *args, **kwargs)
        yield From(future)
        raise Return(stream)
1250316
def worker_thread(context):
    """"""
    queue = context.task_queue
    parameters = context.worker_parameters

    if parameters.initializer is not None:
        if not run_initializer(parameters.initializer, parameters.initargs):
            context.state = ERROR
            return

    for task in get_next_task(context, parameters.max_tasks):
        execute_next_task(task)
        queue.task_done()
1066694
def threaded(
    name: typing.Callable[..., typing.Any], daemon: bool = False, started: bool = False
) -> typing.Callable[..., threading.Thread]:
    """"""