Python join a process without blocking parent

后端 未结 5 1422
孤独总比滥情好
孤独总比滥情好 2020-12-08 16:23

I\'m writing a program that will watch a particular directory for new files containing download URLs. Once a new file is detected, it will create a new process to do the act

5条回答
  •  自闭症患者
    2020-12-08 16:49

    You can also use multiprocessing.Process with deamon=True (daemonic process); the process.start() method does not block so your parent process can continue working without waiting for its child to finish.

    The only caveat is that daemonic processes are not allowed to spawn children.

    from multiprocessing import Process
    
    child_process = Process(
        target=my_func,
        daemon=True
    )
    child_process.start()
    # Keep doing your stuff
    

提交回复
热议问题