Process callbacks from `call_from_executor` in eventloop.
1310
def _process_callbacks(self):
        
        # Flush all the pipe content.
        os.read(self._schedule_pipe[0], 1024)

        # Process calls from executor.
        calls_from_executor, self._calls_from_executor = self._calls_from_executor, []
        for c in calls_from_executor:
            c()
1179881
async def executor(func, *args, **kwargs):
    '''
    
    '''
    def syncfunc():
        return func(*args, **kwargs)

    loop = asyncio.get_running_loop()
    return await loop.run_in_executor(None, syncfunc)
1004519
def invoke(self):
        

        # Don't sleep a hook if it has never run
        if self.timeout_milliseconds > 0:
            self.ready_time = (
                datetime.now() +
                timedelta(milliseconds=self.timeout_milliseconds))

        self.callback(self.callback_args)
564438
def _run_callbacks(self):
        """"""
        for i in range(len(self._callbacks)):
            callback, args = self._callbacks.popleft()
            try:
                callback(*args)
            except Exception:
                self._log.exception('Ignoring exception in callback:')
687744
def execute(self, fn, *args, **kwargs):
        """"""
        if self.in_executor_context():
            return fn(*args, **kwargs)
        task = self.submit(fn, *args, **kwargs)
        return task.result()
193107
def _trigger_event(self, event, *args, **kwargs):
        """"""
        run_async = kwargs.pop('run_async', False)
        if event in self.handlers:
            if run_async:
                return self.start_background_task(self.handlers[event], *args)
            else:
                try:
                    return self.handlers[event](*args)
                except:
                    self.logger.exception(event + ' handler error')
1092844
def running_jobs(self, exit_on_error=True):
        """"""
        with self.handling_exceptions():
            if self.using_jobs:
                from concurrent.futures import ProcessPoolExecutor
                try:
                    with ProcessPoolExecutor(self.jobs) as self.executor:
                        yield
                finally:
                    self.executor = None
            else:
                yield
        if exit_on_error:
            self.exit_on_error()
34377
def exec_hook(event_name, *args, &block)
      @hooks[event_name.to_s].map do |hook_name, callable|
        begin
          callable.call(*args, &block)
        rescue PuppetDebugger::Exception::Error, ::RuntimeError => e
          errors << e
          e
        end
      end.last
    end
225286
def handle_callback(hook, event, *data)
      to = machine.events_map.move_to(event.event_name, event.from, *data)
      trans_event = TransitionEvent.new(event.event_name, event.from, to)
      callable    = create_callable(hook)

      if hook.is_a?(Async)
        defer(callable, trans_event, *data)
      else
        callable.(trans_event, *data)
      end
    end
467508
def handle_basic_executor_options(options, parser):
    """"""
    # setup logging
    logLevel = logging.INFO
    if options.debug:
        logLevel = logging.DEBUG
    elif options.quiet:
        logLevel = logging.WARNING
    util.setup_logging(level=logLevel)
229985
def _processEvents():
    """"""
    global _mousel, _mousem, _mouser, _eventsflushed, _pushedEvents
    _eventsflushed = True
    events = _pushedEvents # get events from event.push
    _pushedEvents = [] # then clear the pushed events queue

    mouse = _ffi.new('TCOD_mouse_t *')
    libkey = _ffi.new('TCOD_key_t *')
    while 1:
        libevent = _lib.TCOD_sys_check_for_event(_lib.TCOD_EVENT_ANY, libkey, mouse)
        if not libevent: # no more events from libtcod
            break

        #if mouse.dx or mouse.dy:
        if libevent & _lib.TCOD_EVENT_MOUSE_MOVE:
            events.append(MouseMotion((mouse.x, mouse.y),
                                      (mouse.cx, mouse.cy),
                                      (mouse.dx, mouse.dy),
                                      (mouse.dcx, mouse.dcy)))

        mousepos = ((mouse.x, mouse.y), (mouse.cx, mouse.cy))

        for oldstate, newstate, released, button in \
            zip((_mousel, _mousem, _mouser),
                (mouse.lbutton, mouse.mbutton, mouse.rbutton),
                (mouse.lbutton_pressed, mouse.mbutton_pressed,
                 mouse.rbutton_pressed),
                (1, 2, 3)):
            if released:
                if not oldstate:
                    events.append(MouseDown(button, *mousepos))
                events.append(MouseUp(button, *mousepos))
                if newstate:
                    events.append(MouseDown(button, *mousepos))
            elif newstate and not oldstate:
                events.append(MouseDown(button, *mousepos))

        if mouse.wheel_up:
            events.append(MouseDown(4, *mousepos))
        if mouse.wheel_down:
            events.append(MouseDown(5, *mousepos))

        _mousel = mouse.lbutton
        _mousem = mouse.mbutton
        _mouser = mouse.rbutton

        if libkey.vk == _lib.TCODK_NONE:
            break
        if libkey.pressed:
            keyevent = KeyDown
        else:
            keyevent = KeyUp

        events.append(
            keyevent(
                libkey.vk,
                libkey.c.decode('ascii', errors='ignore'),
                _ffi.string(libkey.text).decode('utf-8'),
                libkey.shift,
                libkey.lalt,
                libkey.ralt,
                libkey.lctrl,
                libkey.rctrl,
                libkey.lmeta,
                libkey.rmeta,
                )
            )

    if _lib.TCOD_console_is_window_closed():
        events.append(Quit())

    _eventQueue.extend(events)
498964
def run(self):
        ''''''
        while not self.wait(self.delay()):
            try:
                logger.info('Invoking callback %s', self.callback)
                self.callback()
            except StandardError:
                logger.exception('Callback failed')
145214
async def execute(self, fn, *args, **kwargs) -> None:
        ''''''

        fn = functools.partial(fn, *args, **kwargs)
        return await self.loop.run_in_executor(self.executor, fn)
995459
def run_deferred(self, deferred):
        """"""
        for handler, scope, offset in deferred:
            self.scope_stack = scope
            self.offset = offset
            handler()
57909
def invoke(self, ctx):
        
        if self.callback is not None:
            loop = asyncio.get_event_loop()
            return loop.run_until_complete(self.async_invoke(ctx))
1168910
public void callback(final Callback callback)
    {
        Runnable runnable = new Runnable()
        {
            @Override
            public void run()
            {
                try
                {
                    callback.result(queryId, awaitResult());
                }
                catch (Exception e)
                {
                    callback.error(queryId, e);
                }
            }
        };
        EXECUTOR_SERVICE.submit(runnable);
    }
23346
def _setup_eventloop(self):
        
        if os.name == 'nt':
            self.eventloop = asyncio.ProactorEventLoop()
        else:
            self.eventloop = asyncio.new_event_loop()
        asyncio.set_event_loop(self.eventloop)
        if os.name == 'posix' and isinstance(threading.current_thread(), threading._MainThread):
            asyncio.get_child_watcher().attach_loop(self.eventloop)