From fca0ad0ea75be8b07fe92c468c59b7eaf180c7b4 2013-11-16 23:24:53 From: MinRK Date: 2013-11-16 23:24:53 Subject: [PATCH] add utils.pickleutil.use_dill enables dill extended serialization support --- diff --git a/IPython/utils/pickleutil.py b/IPython/utils/pickleutil.py index 33900c2..dc813c8 100644 --- a/IPython/utils/pickleutil.py +++ b/IPython/utils/pickleutil.py @@ -40,6 +40,36 @@ else: class_type = (type, ClassType) #------------------------------------------------------------------------------- +# Functions +#------------------------------------------------------------------------------- + + +def use_dill(): + """use dill to expand serialization support + + adds support for object methods and closures to serialization. + """ + # import dill causes most of the magic + import dill + + # dill doesn't work with cPickle, + # tell the two relevant modules to use plain pickle + + global pickle + import pickle + + try: + from IPython.kernel.zmq import serialize + except ImportError: + pass + else: + serialize.pickle = pickle + + # disable special function handling, let dill take care of it + can_map.pop(FunctionType, None) + + +#------------------------------------------------------------------------------- # Classes #-------------------------------------------------------------------------------