import time
import multiprocessing
class MyProcess(multiprocessing.Process):
def __init__(self, func_name, *args, **kwargs):
self.func_name = func_name
self.args = args
self.kwargs = kwargs
super(MyProcess, self).__init__()
#multiprocessing.Process.__init__(self)
def run(self):
print "begin to run func: %s" % self.func_name.__name__
print self.name
self.func_name(*self.args, **self.kwargs)
print "end to run func: %s" % self.func_name.__name__
def t1(*args, **kwargs):
print "I am t1-xudedong"
time.sleep(5)
def t2(*args, **kwargs):
print "I am t2-xudedong"
print args
print kwargs
time.sleep(2)
if __name__ == "__main__":
l = []
for t in [t1, t2]:
p = MyProcess(t, 1,2,3, a=2,v=3)
p.start()
l.append(p)
for p in l:
p.join()