How do I save the results of a task to the local f...
# ask-community
c
How do I save the results of a task to the local filesystem? Suppose I have a workflow
test.py
Copy code
from prefect import task, Flow
from prefect.engine.results import LocalResult

OUTPUT_DIR = './outputs'


@task(target='x.txt', checkpoint=True, result=LocalResult(dir=OUTPUT_DIR))
def saver():
    return 10


with Flow('example') as flow:
    saved = saver()

flow.run()
when I run
python test.py
I expect a file tree like
Copy code
tree
Copy code
.
├── outputs
│   └── x.txt
└── test.py
but when I run
python test.py
I don't see an
x.txt
file
Copy code
.
├── outputs
└── test.py
I am using
prefect==0.14.12
What do I need to do to get
prefect
to save (and persist) file results?
j
If you're running locally (using
flow.run()
you'll need to enable checkpointing at the config level as well. You can do this through either environment variables or by modifying your
~/.prefect/config.toml
file:
Copy code
# Through environment variables
export PREFECT__FLOWS__CHECKPOINTING=true
Copy code
# ~/.prefect/config.toml
[flows]
checkpointing = true
This setting is off by default for local runs, and on by default for runs using Prefect Cloud/Prefect Server.
c
That fixed it. Thanks!
👍 1