Skip to content Skip to sidebar Skip to footer

Good Example Of Baditem In Dill Module

I'm exploring the detect method of Dill and am looking for a good simple example of a bad item - one that's unpicklable by Dill. I first thought of a process and tried: >>>

Solution 1:

dill.detect.baditems is supposed to check for "bad items" inside of an object (i.e. check what is inside of an object that doesn't pickle). Maybe, at the top level it should check if the object itself pickles… it doesn't currently, and that could be misleading.

Here I'll demonstrate an unpicklable item that baditems says there's nothing unpicklable on the inside, which is true. Then I'll show how baditems finds unpicklable items inside of globals, and correctly identifies what cannot be pickled.

>>>x = iter([1,2,3,4,5])>>>x
<listiterator object at 0x10d743510>
>>>import dill>>># everything inside a listiterator is serializable>>>dill.detect.baditems(x)
[]
>>># however, not everything in globals is serializable>>>dill.detect.baditems(globals())
[<module '__builtin__' (built-in)>, <listiterator object at 0x10d743510>]

Hopefully, this doesn't seem too counter-intuitive.

Post a Comment for "Good Example Of Baditem In Dill Module"