Are there examples of using 1 flow to run 2 subflo...
# ask-community
j
Are there examples of using 1 flow to run 2 subflows in Prefect 2.0? The documentation is not very clear on the matter. How do I test it locally? On my firm's local server?
n
hi @Jason Motley - in prefect 2, you can simply call
@flow
-decorated functions from other
@flow
-decorated functions, for example
Copy code
from prefect import flow

@flow
def foo():
   pass

@flow
def bar():
   for _ in range(3):
      foo()

if __name__ == "__main__":
   bar()
   # deploy this flow with bar.serve(__file__)
will run 3 subflows
which you can then test locally by running the python file
j
what if foo and bar are in different python files?
If most of my flows look like this, do I need to rename
main_flow
? @flow(name="test.test", persist_result=True, log_prints=True) def main_flow(msg="Flow body"):
I'm confused as to what happens if 2 files have the same @flow name in them?
n
just like python otherwise, you can import whatever objects you need, aliasing them as needed
Copy code
from my_module import main_flow as this_specific_main_flow

@flow(name="some unique name")
def main_flow():
   this_specific_main_flow()
is this what you mean? prefect doesn't really care what the
__name__
of your flow function is, but if you're re-using names then I would pass a unique
name
to the decorator of each flow
j
yeah, so do I pass in "some unique name"? or do I pass in "main_flow" ?
and is my_module the actual file name (say locally or in gitlab)?
n
the module import stuff should be entirely consistent with python, as in you could do
Copy code
from my_package.module.submodule import some_defined_flow

# or 

from local_file import some_other_defined_flow
and as for the
name
kwarg to your flow decorator, its entirely up to you what you call your flows, but flows should have unique names
j
is
local_file
the flow name from the file or the actual name (
name="my_name"
)?
n
local_file
is a hypothetical file name in which
some_other_defined_flow
would be defined, like
Copy code
# local_file.py

from prefect import flow

@flow(name="whatever")
def some_other_defined_flow():
   pass
👍 1
j
Along these lines, if "my_file_1.py" is already running _and is part of this subflow, is there a way to skip that part of the refresh until it has finished running?_ Example: Flow 1 runs every hour and it is a subflow for an orchestration that runs every 8 hours. I don't want the overlap to occur every 8 hours.
n
im not sure i totally understand what pattern you're talking about - do you have a code example of what you're trying to do?