]> granicus.if.org Git - python/commitdiff
Issue #14335: multiprocessing's custom Pickler subclass now inherits from the C-accel...
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 16 Mar 2012 23:23:04 +0000 (00:23 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 16 Mar 2012 23:23:04 +0000 (00:23 +0100)
Patch by sbt.

Lib/multiprocessing/forking.py
Misc/NEWS

index b7de5679b1b2f90d56ebc805d489c12d9493c720..020508a11815a3a0457fe8bb54638e10e223ba1a 100644 (file)
@@ -55,18 +55,18 @@ def assert_spawning(self):
 # Try making some callable types picklable
 #
 
-from pickle import _Pickler as Pickler
+from pickle import Pickler
+from copyreg import dispatch_table
+
 class ForkingPickler(Pickler):
-    dispatch = Pickler.dispatch.copy()
+    _extra_reducers = {}
+    def __init__(self, *args):
+        Pickler.__init__(self, *args)
+        self.dispatch_table = dispatch_table.copy()
+        self.dispatch_table.update(self._extra_reducers)
     @classmethod
     def register(cls, type, reduce):
-        def dispatcher(self, obj):
-            rv = reduce(obj)
-            if isinstance(rv, str):
-                self.save_global(obj, rv)
-            else:
-                self.save_reduce(obj=obj, *rv)
-        cls.dispatch[type] = dispatcher
+        cls._extra_reducers[type] = reduce
 
 def _reduce_method(m):
     if m.__self__ is None:
index 470ab420173c905d7be545ccafc5f4263ae8cafc..5672fc31d161a1a6d5acd2764740baf259df367a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #14335: multiprocessing's custom Pickler subclass now inherits from
+  the C-accelerated implementation.  Patch by sbt.
+
 - Issue #10484: Fix the CGIHTTPServer's PATH_INFO handling problem.
 
 - Issue #11199: Fix the with urllib which hangs on particular ftp urls.