Hi Folks, I would like to know how Prefect reacts ...
# ask-community
n
Hi Folks, I would like to know how Prefect reacts to
sys.exit(1)
. I have this line inside of a task and if the execution reaches this line, does it exit with
1
and mark the
task
as successful or failed? Or does it think the
flow
failed and try to restart the
flow
?
Is it recommended to do
raise SystemExit('my error message')
instead of
sys.exit(1)
when I want the task to end with failed status?
k
Hey, what is the intent here? You can raise Prefect signals like
raise FAIL(message)
if you want to fail the task and move on. you can also
raise SKIP
to skip downstream tasks. Docs
Would this fit your use case?
n
Yes, this might work. Could you also share the import statements please?
k
from prefect.engine.signals import FAIL, SKIP, SUCCESS
👍 1
s
@Nivi Mukka For reference, Prefect reacts very poorly to sys.exit calls. It loses the state of the job all together and never marks it as complete or failed since you kill the process and it can't report back. At least with Kubernetes runners anyway
👍 2