【发布时间】:2018-03-26 21:07:27
【问题描述】:
我目前正在编写一个 python3 脚本,该脚本通过运行具有各种输入文件的 C 代码来检查 C 源文件。如果重要,编译由 GCC 完成。 在某些情况下,C 代码进入无限循环(我想通了,因为内存不足)。 有没有办法像看门狗或其他东西一样“保护”我的代码 在 X 分钟后告诉我我遇到了无限循环?
我不能假设任何关于输入的事情,所以我无法得到答案,比如改变它或其他什么......
#runfile is an exe file, code file is .c file, inputlist/outputlist are directories
import subprocess as sbp
import os
sbp.call('gcc -o {0} {1}'.format(runfile,codefile), shell = True)
for i in range(numoFiles):
#run the file with input i and save it to output i in outdir
os.system("./{0} <{1} >{2}".format(ID,inputList[i],outputList[i]))
【问题讨论】:
-
Minimal, Complete, and Verifiable example 请。显示代码的蓝图。
-
既然你已经知道如何使用
subprocess.call,为什么还要使用os.system? -
tripleee,它是一个更大脚本的一部分,所以在我弄清楚如何使用子进程之前,我使用了 os.. 我会改变它..
标签: python-3.x ubuntu gcc infinite-loop