<@ULVA73B9P> I am trying to suspend my flow in the...
# marvin-in-the-wild
j
@Marvin I am trying to suspend my flow in the middle of it's run using
suspend_flow_run(timeout=None)
- however I am running into a
RuntimeError: Flow run cannot be suspended: Cannot suspend flows.
error. Why can I not suspend the flow?
m
It sounds like you’re having trouble using the
suspend_flow_run
function in Prefect. Let me look up some documentation and potential issues that might explain why you're seeing this error. But first, which version of Prefect are you using?
j
2.x @Marvin
m
It looks like the documented usage of
suspend_flow_run
mentions a few crucial points: 1. Out-of-Process Suspension: Flow runs can be suspended out-of-process by calling
suspend_flow_run(flow_run_id=<ID>)
or selecting the Suspend button in the Prefect UI or Prefect Cloud. 2. Distinction from Pausing: Suspending a flow run is different from pausing one. Suspending will tear down the running infrastructure, and resuming the flow will execute it from the beginning. 3. Subflows: Subflows can't be suspended independently of their parent flow runs. You can read more about it here: - Pausing and suspending a flow run - Suspend flow run usage Ensure you're not trying to suspend a subflow independently, and check that you're using the correct method based on whether the function is called within the flow or out-of-process. If none of this resolves your issue, you might want to check your Prefect setup for any misconfigurations or special settings that could prevent suspension.
j
The function is called within the flow @Marvin
m
Got it, you mentioned calling the function within the flow. Make sure you are calling
suspend_flow_run
correctly and you are handling the infrastructure tear down as mentioned. Given this, you might also want to verify if you are dealing with subflows, as they cannot be suspended independently if they are part of a larger flow. Here's a suggested structure for calling
suspend_flow_run
within a flow:
Copy code
python
from prefect import flow, task, suspend_flow_run

@task
def my_task():
    print("Running task")

@flow
def my_flow():
    my_task()
    suspend_flow_run()  # Calling suspend within the flow
    my_task()

my_flow()
Ensure the suspension is not blocked by other parts of the flow or the infrastructure setup. If you're still running into issues, it might be a good idea to review your flow configuration or check for any updates or bug reports related to this feature. For more detailed help, consider raising an issue on the Prefect GitHub or reviewing open issues related to flow suspension: - Prefect GitHub Issues Let me know if you need further assistance!