Riya Sinha
01/18/2025, 8:49 PMclient.create_flow_run_from_deployment
, how do I cancel the run? I don’t want to delete it, just cancel via the python apiMarvin
01/18/2025, 8:49 PMPrefectClient
class from the prefect.client.orchestration
module. Here's a concise example of how you might achieve this:
python
from prefect.client.orchestration import get_client
from prefect.states import Cancelled
async def cancel_flow_run(flow_run_id: str):
async with get_client() as client:
await client.set_flow_run_state(flow_run_id=flow_run_id, state=Cancelled())
# Example usage
import asyncio
flow_run_id = "your-flow-run-id"
asyncio.run(cancel_flow_run(flow_run_id))
This script uses the get_client()
function to interact with the Prefect API and sets the state of the specified flow run to Cancelled
. Remember to replace "your-flow-run-id"
with the actual ID of the flow run you wish to cancel.
For more details on the cancellation process and potential issues, you can refer to the Prefect documentation on cancellation.