Hi All, new to Prefect, can somepoint point me in ...
# ask-community
s
Hi All, new to Prefect, can somepoint point me in the right direction here? In this example, let's say i set each flow to run every 2 seconds, how do i prevent parallel runs of a flow before it finishes, specifically slow() without blocking hello_world()
Copy code
from prefect import flow, task, serve
import time

@flow(log_prints=True)
def hello_world(name: str = "world", goodbye: bool = False):
    x = 1
    s = str(x)
    print(f"Hello {name} {s} from Prefect! :hugging_face:")
    x += 1

    if goodbye:
        print(f"Goodbye {name}!")

@flow(log_prints=True)
def slow():
    time.sleep(100)
    print("ok")

if __name__ == "__main__":
    a_deploy = hello_world.to_deployment(name="hellow")
    b_deploy = slow.to_deployment(name="slow")
    serve(a_deploy, b_deploy)
n
by > how do i prevent parallel runs of a flow before it finishes, specifically slow() without blocking hello_world() do you mean that you only want one run of each flow going at any given time? using
serve
, what you can do is set a
limit
for that process, but that will just limit the number of flow runs that this served process can execute at once, irrespective of which flow(s) is/are being run
s
thanks for the reply Nate, yes I want one run of each flow going at any given So in my setup I'd like one file to have to run on the server (the above code snippet I posted) and since slow() sleeps for 100 seconds if you run the program and set hello_world() and slow() each to run in 1 seconds intervals, it runs both in parallel, but doesn't spawn a new slow() till the one it started finished running