示例
import multiprocessing
import time
cnt = 0
def worker(num):
while True:
global cnt
cnt += 1
print(num, 'Working...', cnt)
time.sleep(num+1)
return
def main():
processes = []
for i in range(5):
p = multiprocessing.Process(target=worker, args=(i,))
processes.append(p)
p.start()
for p in processes:
p.join()
if __name__ == '__main__':
multiprocessing.freeze_support()
main()
input()