(self, queue: InternalQueue, handler, command, on_done: asyncio.Event)
Handle a received command by calling the provided handler

        This execution happens in the background.
Handle a received command by calling the provided handler
Handle a received command by calling the provided handler
def handle_in_background(self, queue: InternalQueue, handler, command, on_done: asyncio.Event):
        """Handle a received command by calling the provided handler

        This execution happens in the background.
        """
        logger.debug(f"Handling command {command}")

        def when_task_finished(fut: asyncio.Future):
            self._running_commands.remove(fut)
            try:
                # Retrieve any error which may have occurred.
                # We ignore the error because we assume any exceptions which the
                # handler threw will have already been placed into the error queue
                # by the queue_exception_checker().
                # Regardless, we must retrieve the result in order to keep Python happy.
                fut.result()
            except:
                pass

            # We use call_soon_threadsafe() to ensure we call the Event's set()
            # in a threadsafe fashion. This is because the Event object may have
            # been created in another thread and be attached to another event loop
            on_done._loop.call_soon_threadsafe(on_done.set)

        # fmt: off
        background_call_task = asyncio.ensure_future(queue_exception_checker(
            handler(command),
            self.error_queue,
        ))
        # fmt: on
        background_call_task.add_done_callback(when_task_finished)
        self._running_commands.add(background_call_task)
def handle_in_background ( self , queue : InternalQueue , handler , command , on_done : asyncio . Event ) : logger . debug ( f"Handling command {command}" ) def when_task_finished ( fut : asyncio . Future ) : self . _running_commands . remove ( fut ) try : # Retrieve any error which may have occurred. # We ignore the error because we assume any exceptions which the # handler threw will have already been placed into the error queue # by the queue_exception_checker(). # Regardless, we must retrieve the result in order to keep Python happy. fut . result ( ) except : pass # We use call_soon_threadsafe() to ensure we call the Event's set() # in a threadsafe fashion. This is because the Event object may have # been created in another thread and be attached to another event loop on_done . _loop . call_soon_threadsafe ( on_done . set ) # fmt: off background_call_task = asyncio . ensure_future ( queue_exception_checker ( handler ( command ) , self . error_queue , ) ) # fmt: on background_call_task . add_done_callback ( when_task_finished ) self . _running_commands . add ( background_call_task )