(callable_, args, kwargs)
Run user provided code

    If the callable is blocking (i.e. a regular function) it will be
    moved to its own thread and awaited. The purpose of this thread is to:

        1. Allow other tasks to continue as normal
        2. Allow user code to start its own event loop where needed

    If an async function is provided it will be awaited as-is, and no
    child thread will be created.

    The callable will be called with the given args and kwargs
Run user provided code
Run user provided code
async def run_user_provided_callable(callable_, args, kwargs):
    """Run user provided code

    If the callable is blocking (i.e. a regular function) it will be
    moved to its own thread and awaited. The purpose of this thread is to:

        1. Allow other tasks to continue as normal
        2. Allow user code to start its own event loop where needed

    If an async function is provided it will be awaited as-is, and no
    child thread will be created.

    The callable will be called with the given args and kwargs
    """
    if asyncio.iscoroutinefunction(callable_):
        try:
            return await callable_(*args, **kwargs)
        except Exception as e:
            exception = e
    else:
        try:
            thread_pool_executor = ThreadPoolExecutor(
                thread_name_prefix="user_provided_callable_tpe"
            )
            future = asyncio.get_event_loop().run_in_executor(
                executor=thread_pool_executor, func=lambda: callable_(*args, **kwargs)
            )
            return await future
        except Exception as e:
            exception = e

    logger.debug(f"Error in user provided callable: {repr(exception)}")
    raise exception
async def run_user_provided_callable ( callable_ , args , kwargs ) : if asyncio . iscoroutinefunction ( callable_ ) : try : return await callable_ ( * args , * * kwargs ) except Exception as e : exception = e else : try : thread_pool_executor = ThreadPoolExecutor ( thread_name_prefix = "user_provided_callable_tpe" ) future = asyncio . get_event_loop ( ) . run_in_executor ( executor = thread_pool_executor , func = lambda : callable_ ( * args , * * kwargs ) ) return await future except Exception as e : exception = e logger . debug ( f"Error in user provided callable: {repr(exception)}" ) raise exception