def mist(f, *args, nodes=12,**kwargs): def keycall(key, dictlist, *args, **kwargs): try: return [getattr(i, key)(*args, **kwargs) for i in list(dictlist)] except: return [i[key](*args, **kwargs) for i in list(dictlist)] def transpose(x): shieldgang=[] zilleum=0 for i in range(len(x[-1])): hot = [i[zilleum] for i in x] shieldgang.append(hot) zilleum = zilleum + 1 return shieldgang def process(func, *args, start_process=1, **kwargs): import multiprocessing process_id = str(generate_one_random_number(20)) while process_id in globals(): process_id = str(generate_one_random_number(20)) globals()[process_id] = "processing" def new_func(func, *args, **kwargs): globals()[process_id] = func(*args,**kwargs) def strand(func, *args, start_process=1, **kwargs): from threading import Thread t = Thread(target=func, args=args, kwargs=kwargs) t.start()if(start_process==1)else(1) return t x = strand(new_func, *tuple([func] + list(args)), start_process=start_process, **kwargs) x.globals = globals x.process_id = process_id def result(self): return self.globals()[self.process_id] bind3(x, result) def tmp(self): while self.is_alive() == True: time.sleep(1) return self.globals()[self.process_id] bind3(x, tmp) return x def generate_one_random_number(digits): x = "" while True: x = x + str(random.choice(list(range(10)))) if len(x) == digits: return x import random def bind3(obj,func): from types import MethodType,ModuleType,FunctionType setattr(obj, func.name, MethodType(func,obj))if(""!=func.name)else(setattr(obj, get_lambda_name(func), MethodType(func,obj))) args = list(args) results = type("list", (list,), dict(result=lambda self: [keycall("join",self),keycall("result",self)][1])) results = results() if args and len(args[0]) == 0: return results from inspect import getfullargspec fullargspec = getfullargspec(f) argcount = f.code.co_argcount if "self" in fullargspec.args: argcount = argcount - 1 accountable_args_len = argcount - (len(kwargs)) breaklen = None args if accountable_args_len == 1: args = args breaklen=len(args) else: args = list(args)[0] breaklen=len(args[0]) args = transpose(args) zilleum = 0 while True: if keycall("result",results).count("processing") < nodes: if accountable_args_len != 0: results.append(process(f,*args[zilleum], **kwargs)) zilleum+=1 elif accountable_args_len == 0: results.append(process(f, **kwargs)) else: time.sleep(0.1) if not args: r = results[0] r.join_saved = r.join r.result_saved = r.result def result(self): self.join() return self.result_saved() is_running = lambda self: self.isAlive() bind3(r, result) bind3(r, is_running) elif zilleum == breaklen: break return results python3.5/windows/no pkgs installed required besides ipython
©