<@ULVA73B9P> does running tasks with .submit() sch...
# ask-marvin
s
@Marvin does running tasks with .submit() schedule them with an async event loop when tasks are async? The doc says submit pushes the tasks to a ThreadPoolTaskRunner. Should I manage my tasks with asyncio instead?
m
In Prefect 3.x, when you use the
.submit()
method for tasks, they are indeed pushed to a
ThreadPoolTaskRunner
by default. This means that tasks are executed in a thread pool, which is not inherently asynchronous in the sense of using an
asyncio
event loop. Instead, it leverages threads to achieve concurrency. If you're working with asynchronous tasks and want to manage them using an
asyncio
event loop, you might consider using
AsyncTaskRunner
instead. This would allow you to leverage Python's
asyncio
capabilities more directly. Here's a brief overview of what you might consider: - ThreadPoolTaskRunner: Good for CPU-bound tasks or when using libraries that are not asynchronous. - AsyncTaskRunner: Suitable for I/O-bound tasks and when you want to take full advantage of Python's
asyncio
features. For more details, you can refer to the Prefect task runners documentation and the Prefect tasks documentation. If you have more specific needs or details about your tasks, feel free to share!
s
lol for future ref that looks like marvin is wrong, the code linked shows the task is dispatched to an asyncrunner