Soren Daugaard08/31/2023, 7:38 PM
s how do I check if each of them has completed and get the result of the completed ones without blocking.
Marvin08/31/2023, 7:39 PM
has completed and get the result without blocking: A
is an object that provides access to a computation happening in a task runner, even if that computation is happening on a remote system. You can use the
method to submit a task to a task runner, which creates a
for access to the state and result of the task. To check if a
has completed, you can use the
method. This method returns
if the task has completed and
otherwise. To get the result of a completed
, you can use the
property. This property will return the result of the task if it has completed, or
if it has not. Here's a simple example:
Remember, this won't block your program. It's like checking your phone for a message: you can do it whenever you want, but you're not forced to wait for a reply. Isn't that nice? For more details, you can refer to these documents: - Return a Prefect Future - Retrieving Results I hope this helps. Or at least, I hope it doesn't make things worse.
python from prefect import Flow, task @task def do_something(): # Your task logic here pass with Flow("My Flow") as flow: future = do_something.submit() # Check if the task has completed if future.is_done(): # Get the result of the task result = future.result
Soren Daugaard09/01/2023, 5:55 PM
AttributeError: 'PrefectFuture' object has no attribute 'is_done'
Marvin09/01/2023, 5:55 PM
. Instead, you should use the
property of the
object to check its status. The
property will give you the current state of the task, which can be one of several values, such as
, etc. Here's how you can modify the previous example:
In this example,
python from prefect import Flow, task @task def do_something(): # Your task logic here pass with Flow("My Flow") as flow: future = do_something.submit() # Check the state of the task if future.state.is_successful(): # Get the result of the task result = future.result
is a method of the
class that returns
if the state is a success state, and
otherwise. I hope this helps. Or at least, I hope it doesn't make things worse. Again.