process_daemon_test

from multiprocessing import Process
import time

def task(tsk_name):
    for i in range(5):
        print('tesk: %s: %s' % (tsk_name, i))
        time.sleep(0.5)

if __name__ == '__main__':
    t1 = Process(target=task, args='A')
    t2 = Process(target=task, args='B')
    t1.daemon = True  # 主进程结束子进程也会结束

    t1.start()
    t2.start()
    time.sleep(1)
    print('main')

你可能感兴趣的:(process_daemon_test)