Hello folks.
What's an accurate way of checking whether an object can be atomically
pickled? When I say "atomically pickled", I mean without considering other
objects it may refer to. For example, this list:
l = [threading.Lock()]
is not a pickleable object, because it refers to a `Lock` which is not
pickleable. But atomically, this list itself is pickleable.
Another example:
x = SomeSimpleObject()
x.file = open('whatever', 'r')
Then `x` *would* be atomically pickleable. It's the `.file` attribute which
isn't.
Another way to think of it would be that if I tried to pickle `x`, the
`pickle` module would choke on `.file`, so we know that `.file` is the
atomically unpickleable one.
So how do you check whether an object is atomically pickleable? (I'm
guessing the check should be done on the class, but I'm not sure.)
I want it to behave like this:
>>> is_atomically_pickleable(3)
True
>>> is_atomically_pickleable(3.1)
True
>>> is_atomically_pickleable([1, 2, 3])
True
>>> is_atomically_pickleable(threading.Lock())
False
>>> is_atomically_pickleable(open('whatever', 'r'))
False
Etc.
I have asked
this<http://stackoverflow.com/questions/4199947/python-checking-if-an-object-is-atomically-pickleable>on
StackOverflow, and even gave a small bounty, but I'm not seeing a good
answer yet. I tried to follow up on the logic in `pickle`, but the code in
that module is horribly unreadable. Basically it uses `obj.__reduce__` and
`obj.__reduce_ex__` to figure out whether the object can be pickled, but it
uses them in tricky ways, and there are special cases too.
Does anyone have an idea what to do?
Ram.
_______________________________________________
Python-il mailing list
[email protected]
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il