Skip to content

Commit

Permalink
Merge pull request #276 from jrbourbeau/include-store
Browse files Browse the repository at this point in the history
Avoid auth error when serializing files across processes
  • Loading branch information
betolink authored Sep 7, 2023
2 parents 95253c0 + d86e470 commit ff4fb5f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions earthaccess/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .daac import DAAC_TEST_URLS, find_provider
from .results import DataGranule
from .search import DataCollections
from .auth import Auth


class EarthAccessFile(fsspec.spec.AbstractBufferedFile):
Expand All @@ -33,7 +34,8 @@ def __getattr__(self, method: str) -> Any:
def __reduce__(self) -> Any:
return make_instance, (
type(self.f),
self.f,
self.granule,
earthaccess.__auth__,
self.f.__reduce__(),
)

Expand Down Expand Up @@ -62,7 +64,14 @@ def multi_thread_open(data: tuple) -> EarthAccessFile:
return fileset


def make_instance(cls: Any, granule: DataGranule, _reduce: Any) -> EarthAccessFile:
def make_instance(
cls: Any, granule: DataGranule, auth: Auth, _reduce: Any
) -> EarthAccessFile:
# Attempt to re-authenticate
if not earthaccess.__auth__.authenticated:
earthaccess.__auth__ = auth
earthaccess.login()

if earthaccess.__store__.running_in_aws and cls is not s3fs.S3File:
# On AWS but not using a S3File. Reopen the file in this case for direct S3 access.
# NOTE: This uses the first data_link listed in the granule. That's not
Expand Down

0 comments on commit ff4fb5f

Please sign in to comment.