Hi all :smile: I have little problem, prefect vers...
# ask-community
e
Hi all ๐Ÿ˜„ I have little problem, prefect version 2.7.8 a flow is defined in test.py which content is very simple:
Copy code
from prefect import flow

@flow
def myflow(x: int):
    return x ** x
I want to run this flow with a deployment so i do the following:
Copy code
from prefect.deployments import Deployment, run_deployment
from test import myflow

deployment = Deployment.build_from_flow(flow=myflow, name="test", version=1)
deployment_uuid = deployment.apply()
output = run_deployment(name=f"{deployment.flow_name}/{deployment.name}", parameters={"x": 3})
Everything works fine, but the program never returns ๐Ÿ˜ข it's stuck on the "run_deployment" When I do
prefect flow-run ls
I see that my flow-run was created but is stuck in "scheduled" state. I have the same problem if I run this code within a "if name == main" block, if I specify a work queue name, or add a schedule time in the future. Do you have any idea ? Thanks in advance for your precious help ๐Ÿ’“
โœ… 1
n
Hi @Ethienne Marcelin are you running an agent?
e
Yes I tried with an agent, and specified the work queue name I started the agent with prefect agent star -q test
n
ahh, try passing
work_queue_name="test"
to your
build_from_flow
call
e
Thatโ€™s what i did but it had no effect :(
n
hmm could you try doing a CLI command just as a sanity check?
Copy code
prefect deployment build test.py:myflow -n test -q test --apply
e
Yes of course ! Iโ€™m in the subway so iโ€™ll try when iโ€™m back home
๐Ÿƒ 2
n
sounds good ๐Ÿ™‚
e
By doing the command provided it works, but I wonder what i'm missing in my code๐Ÿค”
okay, i need to start the agent facepalm sorry
thanks @Nate ๐Ÿ’™
n
sure thing ๐Ÿ˜„ that's why we're here
glad you figured it out
e
Is it possible to start the agent programatically ? Or i must use the CLI ?
n
there's not a python interface for running agents in prefect 2, I'd recommend using the CLI to start the agent process what's your use case that you'd want do it programmatically?
e
i don't want to manage the agent "by hand" with the cli At then end of my program, how do I kill the agent without hitting ctrl-c ? Should I use prefect.infrastructure ?
n
prefect infrastructure is a way of telling your agent how it should actually execute your flow run, if you don't specify infrastructure for a deployment, your agent will assume that it should create a local process (where the agent is running) for your flow run usually agents are meant to be a long-lived process, typically people will start an agent on a VM or a kubernetes pod using the helm chart and just keep it running so it can pick up future flow runs so I guess the short answer is that you would need to manually kill the agent if you only wanted it to exist for the duration of a flow run but its totally valid to just not create a deployment and just run your flow when you want, the runs will still show up in your UI (no agent required) - its just that when you want to attach a schedule or alter flow run parameters from the UI, you'll need a deployment and an agent that can pick up its flow runs
e
Ok I see I misunderstood agents ! You're the best Nate thanks :))
n
sure thing! lmk if any other questions come up