Auto kill process and child process of multiprocessing Pool

前端 未结 1 1782
孤街浪徒
孤街浪徒 2021-02-01 10:13

I am using multiprocessing module for parallel processing. Bellow code snippet search the string filename in X location and return the file name where the string found. But in s

1条回答
  •  遇见更好的自我
    2021-02-01 10:42

    I am able to solve my Issue using psutil module

    Found solution on bellow post:

    import psutil, os
    
    def kill_proc_tree(pid, including_parent=True):    
        parent = psutil.Process(pid)
        for child in parent.get_children(recursive=True):
            child.kill()
        if including_parent:
            parent.kill()
    
    me = os.getpid()
    kill_proc_tree(me)
    

    https://stackoverflow.com/a/4229404/420557

    0 讨论(0)
提交回复
热议问题