(unit: Unit)
Initialize the child process and event loop, then execute the coroutine.
Initialize the child process and event loop, then execute the coroutine.
Initialize the child process and event loop then execute the coroutine .
def run_async(unit: Unit) -> R:
        """Initialize the child process and event loop, then execute the coroutine."""
        try:
            if unit.loop_initializer is None:
                loop = asyncio.new_event_loop()
            else:
                loop = unit.loop_initializer()

            asyncio.set_event_loop(loop)

            if unit.initializer:
                unit.initializer(*unit.initargs)

            result: R = loop.run_until_complete(unit.target(*unit.args, **unit.kwargs))

            return result

        except BaseException:
            log.exception(f"aio process {os.getpid()} failed")
            raise
def run_async ( unit : Unit ) -> R : try : if unit . loop_initializer is None : loop = asyncio . new_event_loop ( ) else : loop = unit . loop_initializer ( ) asyncio . set_event_loop ( loop ) if unit . initializer : unit . initializer ( * unit . initargs ) result : R = loop . run_until_complete ( unit . target ( * unit . args , * * unit . kwargs ) ) return result except BaseException : log . exception ( f"aio process {os.getpid()} failed" ) raise