|  | 
| 23 | 23 | from .errors import EntryNotFoundError, HfHubHTTPError, RepositoryNotFoundError, RevisionNotFoundError | 
| 24 | 24 | from .file_download import hf_hub_url, http_get | 
| 25 | 25 | from .hf_api import HfApi, LastCommitInfo, RepoFile | 
| 26 |  | -from .utils import HFValidationError, hf_raise_for_status, http_backoff, http_stream_backoff | 
|  | 26 | +from .utils import HFValidationError, close_session, hf_raise_for_status, http_backoff, http_stream_backoff | 
| 27 | 27 | 
 | 
| 28 | 28 | 
 | 
| 29 | 29 | # Regex used to match special revisions with "/" in them (see #1710) | 
| @@ -85,8 +85,14 @@ def __init__(cls, *args, **kwargs): | 
| 85 | 85 |         # collecting instances when all other references are gone. To really | 
| 86 | 86 |         # delete a FileSystem, the cache must be cleared. | 
| 87 | 87 |         cls._cache = {} | 
|  | 88 | +        cls._pid = os.getpid() | 
| 88 | 89 | 
 | 
| 89 | 90 |     def __call__(cls, *args, **kwargs): | 
|  | 91 | +        if os.getpid() != cls._pid: | 
|  | 92 | +            # We need to reset the session in case of multiprocessing. | 
|  | 93 | +            # In particular we observed SSL errors and corrupted requests with multiprocessing "fork". | 
|  | 94 | +            close_session() | 
|  | 95 | +            cls._pid = os.getpid() | 
| 90 | 96 |         skip = kwargs.pop("skip_instance_cache", False) | 
| 91 | 97 |         fs_token = cls._tokenize(cls, threading.get_ident(), *args, **kwargs) | 
| 92 | 98 |         fs_token_main_thread = cls._tokenize(cls, threading.main_thread().ident, *args, **kwargs) | 
|  | 
0 commit comments