diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index cdfc1f62..bfb4ff8a 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -802,6 +802,7 @@ class FastPath: True """ + # The following cache is cleared at fork, see os.register_at_fork below @functools.lru_cache() # type: ignore[misc] def __new__(cls, root): return super().__new__(cls) @@ -842,6 +843,10 @@ def mtime(self): def lookup(self, mtime): return Lookup(self) +# Clear FastPath.__new__ cache when forked, avoids trying to re-useing open +# file pointers from zipp.Path/zipfile.Path objects in forked process +os.register_at_fork(after_in_child=FastPath.__new__.cache_clear) + class Lookup: """