python调用进程.start()报错 ...The "freeze_support()" line can be omitted if the program is not going to be frozen to produce an executable.
我的代码
import time
import os
import multiprocessing
def work_a():
for i in range(1, 11):
print('a', i)
time.sleep(1)
def work_b():
for i in range(1, 11):
print('b', i)
time.sleep(1)
start = time.time()
a_p = multiprocessing.Process(target=work_a)
a_p.start()
work_b()
print("消耗的时间为{}".format(time.time() - start))
print(os.getpid())
:修改后
import time
import os
import multiprocessing
def work_a():
for i in range(1, 11):
print('a', i)
time.sleep(1)
def work_b():
for i in range(1, 11):
print('b', i)
time.sleep(1)
if __name__ == '__main__':
start = time.time()
a_p = multiprocessing.Process(target=work_a)
a_p.start()
work_b()
print("消耗的时间为{}".format(time.time() - start))
print(os.getpid())
修改后就可以正常运行了,希望有懂的大神解释下。