prefect.utilities.asyncutils
get_thread_limiter
is_async_fn
True
if a function returns a coroutine.
See https://github.com/microsoft/pyright/issues/2142 for an example use
is_async_gen_fn
True
if a function is an async generator.
create_task
run_coro_as_sync
coroutine
: The coroutine to be run as a synchronous function.force_new_thread
: If True, the coroutine will always be run in a new thread.
Defaults to False.wait_for_result
: If True, the function will wait for the coroutine to complete
and return the result. If False, the function will submit the coroutine to the “run sync”
event loop and return immediately, where it will eventually be run. Defaults to True.run_sync_in_worker_thread
call_with_mark
run_async_from_worker_thread
run_async_in_new_loop
mark_as_worker_thread
in_async_worker_thread
in_async_main_thread
sync_compatible
@sync_compatible
are synchronous. If
you want to use the decorated function in an async context, you will need to ignore the types
and “cast” the return type to a coroutine. For example:
asyncnullcontext
sync
add_event_loop_shutdown_callback
asyncio.run()
which waits for async generator shutdown by
default or explicit call of asyncio.shutdown_asyncgens()
. If the application
is entered with asyncio.run_until_complete()
and the user calls
asyncio.close()
without the generator shutdown call, this will not trigger
callbacks.
asyncio does not provided any other way to clean up a resource when the event
loop is about to close.
create_gather_task_group
gather
asyncio.gather
this expects to receive callables not coroutines.
This matches anyio
semantics.
GatherIncomplete
GatherTaskGroup
gather
support. This class extends the TaskGroup
interface to allow simple gathering.
See https://github.com/agronholm/anyio/issues/100
This class should be instantiated with create_gather_task_group
.
Methods:
get_result
start
start
returns the result of task_status.started()
but here we must
return the key instead, we just won’t support this method for now.
start_soon
LazySemaphore