python 多进程

import multiprocessing
import time
a = 1

def add_a1():
# print("这里是进程:", i)
time.sleep(3)
global a
for i in range(10000000):
a += i
print(a)

def write_to_file():
f = open("data.txt","w")
f.write("1111")
f.write("1111")
f.write("1111")
f.write("1111")
f.write("1111")
f.write("1111")
f.write("1111")
f.write("1111")
f.write("1111")
f.close()

if __name__ == '__main__':
for i in range(5):
m = multiprocessing.Process(target=add_a1) # 多进程
m.start()
print(m.pid)
# print(multiprocessing.active_children())
while multiprocessing.active_children() != []:
pass
print("stop")

上一篇:B. I Hate 1111


下一篇:IP分类及配置