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.

Title: Make urllib2.OpenerDirector instances pickle-able
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jjlee, loewis
Priority: normal Keywords: patch

Created on 2005-02-20 02:48 by jjlee, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
pickleable.diff jjlee, 2005-02-20 02:48
Messages (4)
msg47823 - (view) Author: John J Lee (jjlee) Date: 2005-02-20 02:48
urllib2.OpenerDirector would be pickleable if it were
not for the fact that a couple of urllib2 handlers
(which build_opener() adds by default) have function
instance attributes.

It's trivial to replace these instance attributes with
a method that delegates to the appropriate function,
thus allowing pickling.
msg47824 - (view) Author: John J Lee (jjlee) Date: 2005-03-04 18:46
Logged In: YES 

Hmm, maybe this fault (can't pickle) will be fixed without
need for this patch in 2.5, due to the change to unbound
methods that was discussed on python-dev.  I don't
understand that issue, so I can't say.
msg47825 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-02-14 10:27
The patch doesn't fix the problem; the opener remains unpicklable. If you are still interested in this patch, please revise it accordingly; if not, please close it. When you revise it, please include a test case, like this one:

    def test_1144636(self):
        # Make sure OpenerDirector instances can be pickled
        import pickle
        except pickle.PicklingError:
  "cannot pickle OpenerDirector instances")
msg47826 - (view) Author: John J Lee (jjlee) Date: 2007-02-14 21:43
I am no longer convinced that the intended change is an improvement, so I am closing this tracker item.

FWIW, mysteriously, your unit test always *passes* for me (both before and after applying the patch).  (And before svn updating from roughly rev 53200, your unit test fails for me before applying the patch, and passes for me after applying the patch.)

For the record, the reasons I'm no longer convinced that pickle-ability of urllib2.OpenerDirector instances is a good thing are:

1. I don't think a pickle-ability constraint should be imposed on subtypes

2. I'm not convinced now that the ability to pickle these instances is terribly useful (although I did file the patch as a result of a user request)
Date User Action Args
2022-04-11 14:56:09adminsetgithub: 41606
2005-02-20 02:48:45jjleecreate