Calvin Pritchard

    Calvin Pritchard

    1 year ago
    How do I save the results of a task to the local filesystem? Suppose I have a workflow
    test.py
    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
    tree
    .
    ├── outputs
    │   └── x.txt
    └── test.py
    but when I run
    python test.py
    I don't see an
    x.txt
    file
    .
    ├── 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?
    Jim Crist-Harif

    Jim Crist-Harif

    1 year ago
    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:
    # Through environment variables
    export PREFECT__FLOWS__CHECKPOINTING=true
    # ~/.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.
    Calvin Pritchard

    Calvin Pritchard

    1 year ago
    That fixed it. Thanks!