Rok*_*Rok 1 python unix subprocess signals
我有一个python脚本,它等待一些工作并在线程中执行它们(使用subprocess.Popenwith shell=True).当我在shell中运行脚本并尝试终止它时,Ctrl-C它会正常且干净地关闭.
问题是我想将此脚本作为守护程序运行,然后使用某种unix信号终止它.INT信号应该相同Ctrl-C但不能以相同的方式工作.它使子进程subproces.popen运行.
KeyboardInterupt当我收到信号时,我也试过在主线程中加注,但是也无法关闭脚本并杀死所有子进程.
任何建议如何模仿Ctrl-C?
致电subprocess.popen:
shell_cmd = "bwa aln -t 8 file1.fasta file1.fastq.gz > file1.sam.sai"
process = subprocess.Popen(shell_cmd,
shell=True,
stderr=subprocess.PIPE)
Run Code Online (Sandbox Code Playgroud)
KeyboardInterrupt主要过程KeyboardInterrupt中的提升在主要过程中提升.您必须将信号发送到子进程.
你试过Popen.send_signal吗?
或者,更直接,Popen.terminate?