Home  >  Q&A  >  body text

python3.x - Python多进程的子进程终止问题

PHPzPHPz2764 days ago954

reply all(3)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:00:08

    You can use pool.terminate() to end the child process.
    https://docs.python.org/3/lib...

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 10:00:08

    .close() gently stops the child process, .terminate() forcefully closes it.

    I don’t know what usage scenario you need to use this function explicitly. I have never had this need when using concurrent.futures, so I use the with statement directly. After the task is processed, it will exit.

    reply
    0
  • PHPz

    PHPz2017-04-18 10:00:08

    ###  example
    import os
    import signal
    
    def handle_sigterm(signum, frame):
        # do stuff
        os._exit(0)
    
    # subprocess
    signal.signal(signal.SGITERM, handle_sigterm)
    
    # where to kill subprocess
    os.kill(pid, signal.SIGTERM)

    reply
    0
  • Cancelreply