Skip to content

Allow the RefResolver to be pickled #682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions jsonschema/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,18 @@ def __init__(
self._urljoin_cache = urljoin_cache
self._remote_cache = remote_cache

def __getstate__(self):
d = dict(self.__dict__)
# LRU caches don't pickle.
d.pop("_urljoin_cache", None)
d.pop("_remote_cache", None)
return d

def __setstate__(self, state):
self.__dict__.update(state)
self._urljoin_cache = lru_cache(1024)(urljoin)
self._remote_cache = lru_cache(1024)(self.resolve_from_url)

@classmethod
def from_schema(cls, schema, id_of=_id_of, *args, **kwargs):
"""
Expand Down