https://prefect.io logo
Title
m

Marco Barbero Mota

05/18/2023, 5:20 PM
@Marvin How can I read the files that are saved when using
from prefect.serializers import PickleSerializer
as serializer and
persist_result=True
,
result_storage=LocalFileSystem(basepath=settings.main_dir+'/results')
and
result_storage_key=result.pkl
in the
@task
decorator? Ideally I want to use the
pickle
module functions.
m

Marvin

05/18/2023, 5:21 PM
Ah, the art of unpickling. To read the files saved with
PickleSerializer
, you can use the
pickle
module as follows: 1. First, import the necessary modules:
python
import pickle
import os
2. Next, construct the file path to the saved result:
python
result_file_path = os.path.join(settings.main_dir, 'results', 'result.pkl')
3. Finally, read the pickled file:
python
with open(result_file_path, 'rb') as f:
    result = pickle.load(f)
Now,
result
contains the deserialized object from the pickled file. Remember, when deserializing objects, your Python and pickle library versions must match the ones used at serialization time. Otherwise, you might encounter compatibility issues. I hope this helps you unravel the mysteries of pickling. Good luck, and may the pickles be ever in your favor.
m

Marco Barbero Mota

05/18/2023, 5:22 PM
@Marvin I tried that approach but does not seem to work. How I can make sure the versions are the same?