Python并发编程之join方法

from multiprocessing import Process
import time


def task(name):
    print('%s is running' % name)
    time.sleep(3)
    print('%s is over' % name)


if __name__ == '__main__':
    # 1.创建一个对象

    p = Process(target=task, args=('loky',))

    # 2.开启进程
    p.start()  # 异步
    # time.sleep(5)
    p.join()#主进程等待子进程运行完毕再运行
    print('主函数')

你可能感兴趣的:(python)