[英]Python kill bash while loop started from subprocess
我正在嘗試while :; do afplay beep.wav ; done
執行bash腳本while :; do afplay beep.wav ; done
while :; do afplay beep.wav ; done
從python腳本while :; do afplay beep.wav ; done
命令,但之后可以將其殺死。
我試過了:
process = subprocess.Popen("exec while :; do afplay %s ; done" % fileName, shell=True, executable='/bin/bash')
就像這個答案所暗示的那樣,但以上內容對我不起作用。 (腳本無法運行。)
我如何while :; do afplay beep.wav ; done
運行while :; do afplay beep.wav ; done
while :; do afplay beep.wav ; done
從python while :; do afplay beep.wav ; done
並在啟動后隨時將其殺死?
編輯 :只是注意到exec >(while :; do afplay %s; done)
將啟動腳本,但是現在process.kill()
不會殺死它。
os.killpg(os.getpgid(process.pid), signal.SIGINT)
這似乎可以解決問題。 我要殺死進程組( os.killpg
)而不是唯一的進程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.