简体   繁体   English

dill 与 Python 的 pickle 模块有何不同?

[英]How is dill different from Python's pickle module?

I have a large object in my Python3 code which, when tried to be pickled with the pickle module throws the following error:我的 Python3 代码中有一个大的 object ,当尝试使用pickle模块腌制时会引发以下错误:

TypeError: cannot serialize '_io.BufferedReader' object

However, dill.dump() and dill.load() are able to save and restore the object seamlessly.然而, dill.dump()dill.load()能够无缝地保存和恢复 object。

  1. What causes the trouble for the pickle module?是什么导致pickle模块出现问题?
  2. Now that dill saves and reconstructs the object without any error, is there any way to verify if the pickling and unpickling with dill went well?现在dill保存并重建 object 没有任何错误,有什么方法可以验证dill的酸洗和解酸是否顺利?
  3. How's it possible that pickle fails, but dill succeeds? pickle怎么可能失败,但dill成功了?

I'm the dill author.我是dill作者。

1) Easiest thing to do is look at this file: https://github.com/uqfoundation/dill/blob/master/dill/_objects.py , it lists what pickle can serialize, and what dill can serialize. 1) 最简单的方法是查看这个文件: https://github.com/uqfoundation/dill/blob/master/dill/_objects.py ,它列出了pickle可以序列化的内容,以及dill可以序列化的内容。

2) you can try dill.copy and dill.check and dill.pickles to check different levels of pickling and unpickling. 2)您可以尝试dill.copydill.checkdill.pickles来检查不同级别的酸洗和解酸。 dill also more includes utilities for detecting and diagnosing serialization issues in dill.detect and dill.pointers . dill还包括用于检测和诊断dill.detectdill.pointers中的序列化问题的实用程序。

3) dill is built on pickle , and augments it by registering new serialization functions. 3) dill建立在pickle之上,并通过注册新的序列化函数来增强它。

4) dill includes serialization variants which enable the user to choose from different object dependency serialization strategies (in dill.settings ) -- including source code extraction and object reconstitution with dill.source (and extension of the stdlib inspect module). 4) dill包括序列化变体,使用户能够从不同的 object 依赖序列化策略中进行选择(在dill.settings中)——包括源代码提取和 object 用dill.source重构(以及 stdlib inspect模块的扩展)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM