Using module 'subprocess' with timeout

后端 未结 29 2372
旧巷少年郎
旧巷少年郎 2020-11-21 15:15

Here\'s the Python code to run an arbitrary command returning its stdout data, or raise an exception on non-zero exit codes:

proc = subprocess.P         


        
29条回答
  •  囚心锁ツ
    2020-11-21 16:01

    The solution I use is to prefix the shell command with timelimit. If the comand takes too long, timelimit will stop it and Popen will have a returncode set by timelimit. If it is > 128, it means timelimit killed the process.

    See also python subprocess with timeout and large output (>64K)

提交回复
热议问题