You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
S3 Paths change local cache dir after pickling #504
I noticed that S3Paths change their local cache dir of the attached S3Client when pickled.
The S3Client itself appears not to be pickleable due to boto sessions not being pickleable, however, the S3Path even with explicitly specified client is pickleable without throwing errors or warnings.
This is a major problem in multiprocessing for me where pickling is necessary. Here files are then downloaded again instead of using the cached version.
I saw #450 but encounter the error both for version 0.19 and 0.20 (python 3.10.16)
Steps to reproduce
importcloudpathlibascl# get s3 client from somewheredeftest_s3_pickled_client(s3_client: cl.S3Client) ->None:
path=cl.S3Path("s3://dummy", client=s3_client)
path_re=pickle.loads(pickle.dumps(path))
assertpath_re.client._local_cache_dir==path.client._local_cache_dir# fails
@pjbull thanks for the docs, indeed I missed that.
Trying setting the client as default did not work for me, however I don't know if thats some extra magic going on in multiprocessing (via joblib) or if I did something wrong.
For the moment I use this workaround by subclassing S3Path:
@Haydnspass Do you have a minimally reproducible example we could work with to see what's happening with the multiprocessing? There might be potential workarounds or enhancements we want to do.
Activity
pjbull commentedon Feb 25, 2025
Thanks @Haydnspass, did you see these docs on pickling/unpickling?
https://cloudpathlib.drivendata.org/stable/authentication/#pickling-cloudpath-objects
Another option is to set the env var for the local cache dir:
https://cloudpathlib.drivendata.org/stable/caching/#keeping-the-cache-around
Let me know if either of these options address your scenario.
Haydnspass commentedon Feb 27, 2025
@pjbull thanks for the docs, indeed I missed that.
Trying setting the client as default did not work for me, however I don't know if thats some extra magic going on in multiprocessing (via joblib) or if I did something wrong.
For the moment I use this workaround by subclassing S3Path:
I'll follow up
pjbull commentedon Feb 27, 2025
@Haydnspass Do you have a minimally reproducible example we could work with to see what's happening with the multiprocessing? There might be potential workarounds or enhancements we want to do.
Haydnspass commentedon Mar 28, 2025
@pjbull sorry for getting back to you late.
Hmm, indeed i thought my parallel processing using joblib is the problem, but that appears not to be the case in my minimal example here:
So I figure it could be a combination of joblib and pytorch multiprocessing but I will have to further investigate.
fix: resolve issue drivendataorg#504 - preserve explicit persistent l…
docs: add HISTORY.md UNRELEASED entry for issue drivendataorg#504 fix
docs: restore full HISTORY.md (keep drivendataorg#504 UNRELEASED entry)
docs: restore complete HISTORY.md with only the issue drivendataorg#504…
fix: resolve issue drivendataorg#504 - preserve explicit persistent l…