From 9f3ece952f9c6f0ed7a3a5cfdb9445972017b23a Mon Sep 17 00:00:00 2001 From: NickFillot <40593450+NickFillot@users.noreply.github.com> Date: Wed, 25 Aug 2021 09:47:44 +0200 Subject: [PATCH] Custom pickling doc --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index bb8a2a0f..049761fb 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,20 @@ With trace, we see how ``dill`` stored the lambda (``F1``) by first storing (which is used to handle code objects), then we handle the reference to the global dict (``D2``). A ``#`` marks when the object is actually stored. +Custom pickling + +```python +import dill +from sqlalchemy import create_engine +from sqlalchemy.engine import Engine + +@dill.register(Engine) +def save_sqlalchemy_engine(pickler, obj): + pickler._byref = getattr(pickler, '_byref', False) + pickler._recurse = getattr(pickler, '_recurse', False) + pickler.save_reduce(create_engine, (obj.url,), obj=obj) +``` + More Information ----------------