进程
进程 python3.8 官方文档 (opens new window)
# 进程用法
from multiprocessing import Process
# 进程的方法大部分跟线程类似
class MyProcess(Process):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def run(self) -> None:
print('进程{}:{}'.format(self.name, self.pid))
if __name__ == '__main__':
# 进程调用需要放到main中执行,不然会报错
m1 = MyProcess(name='1')
m2 = MyProcess()
m1.start()
m2.start()
m1.join()
m1.close()
m2.join()
m2.close()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
上次更新: 2023/09/04, 18:39:45