Skip to content

Commit 22b777d

Browse files
HyukjinKwonrgbkrk
authored andcommitted
Catchs the exception from pickle.whichmodule()
1 parent e6de4f4 commit 22b777d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cloudpickle/cloudpickle.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,12 @@ def save_function(self, obj, name=None):
310310

311311
if name is None:
312312
name = obj.__name__
313-
modname = pickle.whichmodule(obj, name)
313+
try:
314+
# whichmodule() could fail, see
315+
# https://bitbucket.org/gutworth/six/issues/63/importing-six-breaks-pickling
316+
modname = pickle.whichmodule(obj, name)
317+
except Exception:
318+
modname = None
314319
# print('which gives %s %s %s' % (modname, obj, name))
315320
try:
316321
themodule = sys.modules[modname]
@@ -594,7 +599,12 @@ def save_global(self, obj, name=None, pack=struct.pack):
594599

595600
modname = getattr(obj, "__module__", None)
596601
if modname is None:
597-
modname = pickle.whichmodule(obj, name)
602+
try:
603+
# whichmodule() could fail, see
604+
# https://bitbucket.org/gutworth/six/issues/63/importing-six-breaks-pickling
605+
modname = pickle.whichmodule(obj, name)
606+
except Exception:
607+
modname = '__main__'
598608

599609
if modname == '__main__':
600610
themodule = None

0 commit comments

Comments
 (0)