Tag:sys append python children execution super field elf method
import multiprocessing as mpfrom multiprocessing import processclass Myprocess (process): "" " custom multi-process, inherited from native process, to get multi-process results to queue "" " def __init__ (SELF, FUNC, ARGS, Q): super (myprocess, self). __init__ () self.func = func self.args = args self.res = ' self.q = q #self. _ daemonic = true #self. _daemonic = true def run (self): self.res = self.func (*self.args) &Nbsp; self.q.put ((self.func.__name__, self.res)) def Use_multiprocessing (func_list): #os. System (' export pythonoptimize=1 ') # Solutions daemonic processes are not allowed to have children Issues q = mp. Queue () # queues, storing multi-process results here, inter-process sharing, multi-process must use multiprocessing queue proc_list = [] res = [] for func in func_list: proc = myprocess ( func[' func '], args=func[' args '], q=q) proc.start () proc_list.append (proc) for p In proc_list: p.join () while not q.empty (): r = q.get () res.append (R) return res when used, the parameters of functions and functions that require multi-process execution are treated as fields, and a list is passed to the use_multiprocessing method.
Python multi-process using function encapsulation