-
-
Save pzelasko/90c1c13acd86f6c9c0aa4a3fa69dadba to your computer and use it in GitHub Desktop.
Debug unpickled errors.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from http://stackoverflow.com/questions/569754/how-to-tell-for-which-object-attribute-pickle-fails | |
""" | |
Show which fields cannot be pickled | |
""" | |
import pickle | |
def get_pickling_errors(obj,seen=None): | |
if seen is None: | |
seen = [] | |
try: | |
state = obj.__getstate__() | |
except AttributeError: | |
return | |
if state is None: | |
return | |
if isinstance(state,tuple): | |
if not isinstance(state[0],dict): | |
state=state[1] | |
else: | |
state=state[0].update(state[1]) | |
result = {} | |
for i in state: | |
try: | |
pickle.dumps(state[i],protocol=2) | |
except pickle.PicklingError: | |
if not state[i] in seen: | |
seen.append(state[i]) | |
result[i]=get_pickling_errors(state[i],seen) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment