Skip to content

Instantly share code, notes, and snippets.

@daTokenizer
Last active November 17, 2015 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daTokenizer/6e631bb1d1b6afb3e8d6 to your computer and use it in GitHub Desktop.
Save daTokenizer/6e631bb1d1b6afb3e8d6 to your computer and use it in GitHub Desktop.
a skeleton for a functional usage of the python multiprocessing map functionality
from multiprocessing import Pool
DEFAULT_VALUE = thing
class MapRunner(object):
def __init__(self):
p = pool(i,init_globals)
def init_globals():
global g1
global g2
g1 = somthing
g2 = whatever
def run():
p.map(f,X_collection)
def f(x):
try:
a = w(x,g1)
b = y(x+a)
return z(x,g2)
except:
return DEFAULT_VALUE
class Mappable(object):
def w(x,g):
pass
def y(x):
pass
def z(w,g)
pass
# Note these two functions should basically be copied as is..
def _pickle_method(method):
func_name = method.im_func.__name__
obj = method.im_self
cls = method.im_class
return _unpickle_method, (func_name, obj, cls)
def _unpickle_method(func_name, obj, cls):
for cls in cls.mro():
try:
func = cls.__dict__[func_name]
except KeyError:
pass
else:
break
return func.__get__(obj, cls)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment