Skip to content

Commit 177b790

Browse files
committed
reset https client on multiprocessing
1 parent 82a58ee commit 177b790

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/huggingface_hub/hf_file_system.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from .errors import EntryNotFoundError, HfHubHTTPError, RepositoryNotFoundError, RevisionNotFoundError
2424
from .file_download import hf_hub_url, http_get
2525
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
2727

2828

2929
# Regex used to match special revisions with "/" in them (see #1710)
@@ -85,8 +85,14 @@ def __init__(cls, *args, **kwargs):
8585
# collecting instances when all other references are gone. To really
8686
# delete a FileSystem, the cache must be cleared.
8787
cls._cache = {}
88+
cls._pid = os.getpid()
8889

8990
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()
9096
skip = kwargs.pop("skip_instance_cache", False)
9197
fs_token = cls._tokenize(cls, threading.get_ident(), *args, **kwargs)
9298
fs_token_main_thread = cls._tokenize(cls, threading.main_thread().ident, *args, **kwargs)

0 commit comments

Comments
 (0)