有没有办法通过command timeout
选项proc = subprocess.Popen(cmd.split(' '), stderr=subprocess.PIPE)
来终止无限期挂起的命令
import signal, os
import sys
import subprocess
import argparse
from subprocess import Popen, PIPE, STDOUT
import threading
from time import sleep
import time
from subprocess import Popen, PIPE, STDOUT
cmd = "python script.py -m loc"
proc = subprocess.Popen(cmd.split(' '), stderr=subprocess.PIPE)
print "Executing %s"%cmd
with proc.stderr:
for line in iter(proc.stderr.readline, b''):
print line,
print "process is done..." #doesn't print when command is hung
更新: -
我查看了以下门票,我没有找到关于如何使用subprocess32
的明确示例,我在python文档中搜索过,仍然无法找到