Skip to content

Instantly share code, notes, and snippets.

@MetroWind
Last active March 2, 2016 17:08
Show Gist options
  • Save MetroWind/5697a68fdf56e7f3f9f6 to your computer and use it in GitHub Desktop.
Save MetroWind/5697a68fdf56e7f3f9f6 to your computer and use it in GitHub Desktop.
Make multiprocessing work with methods #python
# Make multiprocessing work with methods. Add this to the beginning of file.
if sys.version_info.major == 2:
import copy_reg as CReg
else:
import copyreg as CReg
import types
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)
CReg.pickle(types.MethodType, _reduce_method)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment