Python 多进程_创建
1. 进程的创建方式1
from multiprocessing import Process import time def func(thread_name): print(thread_name) time.sleep(2) if __name__ == '__main__': p = Process(target=func, args=('process_1',)) p2 = Process(target=func, args=('process_2',)) p.start() p2.start()
2. 进程的创建方式2
from multiprocessing import Process import time class MyProcess(Process): def __init__(self,thread_name): super(MyProcess,self).__init__() self.thread_name=thread_name def run(self): print(self.thread_name) time.sleep(2) if __name__ == '__main__': p = MyProcess('process_1') p2 =MyProcess('process_2') p.start() p2.start()