child subprocess kill in python daemon

后端 未结 1 1665
借酒劲吻你
借酒劲吻你 2021-01-13 06:41

I have damon in python which runs external program:

subprocess.call([\"java\", \"-jar\", \"start.jar\"])

when I kill daemon, the child proc

相关标签:
1条回答
  • 2021-01-13 07:11

    Use subprocess.Popen() instead of subprocess.call(). For example:

    import subprocess
    my_process = subprocess.Popen(['ls', '-l'])
    

    To terminate the child:

    my_process.kill()
    

    To capture the kill signal, you could so something like this:

    import signal
    import sys
    def signal_handler(signal, frame):
        sys.exit(0)
    signal.signal(signal.SIGINT, signal_handler)
    
    0 讨论(0)
提交回复
热议问题