This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: __reduce_ex__ on lock object
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: cool-RR, pitrou, rhettinger
Priority: normal Keywords:

Created on 2013-09-16 00:43 by cool-RR, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (7)
msg197850 - (view) Author: Ram Rachum (cool-RR) * Date: 2013-09-16 00:43
>>> import threading
    >>> l = threading.Lock()
    >>> l.__reduce_ex__(3)
    (<function __newobj__ at 0x00000000026CD8C8>,
     (<class '_thread.lock'>,),
     None,
     None,
     None)

Isn't it a bug that `__reduce_ex__` works on the non-pickleable lock object?
msg197880 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-09-16 08:40
I don't really know. It simply looks like the default implementation of __reduce_ex__. Is it important?
msg197887 - (view) Author: Ram Rachum (cool-RR) * Date: 2013-09-16 10:29
I use that to test whether an object is pickleable or not. It used to work in Python 2.
msg197892 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-09-16 11:36
> I use that to test whether an object is pickleable or not. It used to
> work in Python 2.

Well, the obvious way to do it would be to call pickle.dumps() on
the object, IMO :-)
msg197893 - (view) Author: Ram Rachum (cool-RR) * Date: 2013-09-16 11:38
Wrong, because the object itself could be pickleable but refer to a different object which is non-pickleable. I want to know whether the object itself, without any object it refers to, is pickleable.

Also, pickling an object could be very resource-intensive, depending on its size.
msg197895 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-09-16 12:45
> Wrong, because the object itself could be pickleable but refer to a
> different object which is non-pickleable. I want to know whether the
> object itself, without any object it refers to, is pickleable.

I think you're being too picky. Unless you're manually added stuff
to your Lock's attributes, there isn't a practical difference between
the two situations.

> Also, pickling an object could be very resource-intensive, depending
> on its size.

Well, this is a Lock here, not an ISO file.
msg198005 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2013-09-18 06:43
This does not look like a bug to me.
I think this should be closed.
History
Date User Action Args
2022-04-11 14:57:51adminsetgithub: 63232
2013-09-18 08:56:38cool-RRsetstatus: open -> closed
2013-09-18 06:43:39rhettingersetnosy: + rhettinger
messages: + msg198005
2013-09-16 12:45:49pitrousetmessages: + msg197895
2013-09-16 11:38:45cool-RRsetmessages: + msg197893
2013-09-16 11:36:12pitrousetmessages: + msg197892
2013-09-16 10:29:32cool-RRsetmessages: + msg197887
2013-09-16 08:40:25pitrousetnosy: + pitrou
messages: + msg197880
2013-09-16 00:43:04cool-RRcreate