This module contains methods for object serialization.

Instead of importing serialization functions from Python’s pickle module directly, you should use the dump, dumps, load, loads functions defined here. In particular, these methods will use dumps_function to serialize function objects which cannot be pickled by Python’s standard methods. Note, however, pickling such methods should be avoided since the implementation of dumps_function uses non-portable implementation details of CPython to achieve its goals.

Module Contents

class pymor.core.pickle.Module(mod)[source]
pymor.core.pickle.dump(obj, file, protocol=None)[source]

Tries hard to pickle a function object:

  1. The function’s code object is serialized using the marshal module.

  2. For all global names used in the function’s code object the corresponding object in the function’s global namespace is pickled. In case this object is a module, the modules __package__ name is pickled.

  3. All default arguments are pickled.

  4. All objects in the function’s closure are pickled.

Note that also this is heavily implementation specific and will probably only work with CPython. If possible, avoid using this method.


Restores a function serialized with dumps_function.


Class decorator to mark a class as unpicklable.