mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Apply Amaury's patch to multiprocessing for issue 3125, removes the copy_reg and replaces it with ForkingPickler.register(), which should resolve the conflict with the global registry/ctypes
This commit is contained in:
parent
a6c5dc07f4
commit
13e9d582fd
6 changed files with 69 additions and 57 deletions
|
@ -8,7 +8,6 @@
|
|||
|
||||
import itertools
|
||||
import weakref
|
||||
import copy_reg
|
||||
import atexit
|
||||
import threading # we want threading to install it's
|
||||
# cleanup function before multiprocessing does
|
||||
|
@ -302,35 +301,3 @@ class ForkAwareLocal(threading.local):
|
|||
register_after_fork(self, lambda obj : obj.__dict__.clear())
|
||||
def __reduce__(self):
|
||||
return type(self), ()
|
||||
|
||||
#
|
||||
# Try making some callable types picklable
|
||||
#
|
||||
|
||||
def _reduce_method(m):
|
||||
if m.im_self is None:
|
||||
return getattr, (m.im_class, m.im_func.func_name)
|
||||
else:
|
||||
return getattr, (m.im_self, m.im_func.func_name)
|
||||
copy_reg.pickle(type(Finalize.__init__), _reduce_method)
|
||||
|
||||
def _reduce_method_descriptor(m):
|
||||
return getattr, (m.__objclass__, m.__name__)
|
||||
copy_reg.pickle(type(list.append), _reduce_method_descriptor)
|
||||
copy_reg.pickle(type(int.__add__), _reduce_method_descriptor)
|
||||
|
||||
def _reduce_builtin_function_or_method(m):
|
||||
return getattr, (m.__self__, m.__name__)
|
||||
copy_reg.pickle(type(list().append), _reduce_builtin_function_or_method)
|
||||
copy_reg.pickle(type(int().__add__), _reduce_builtin_function_or_method)
|
||||
|
||||
try:
|
||||
from functools import partial
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
def _reduce_partial(p):
|
||||
return _rebuild_partial, (p.func, p.args, p.keywords or {})
|
||||
def _rebuild_partial(func, args, keywords):
|
||||
return partial(func, *args, **keywords)
|
||||
copy_reg.pickle(partial, _reduce_partial)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue