我正在使用PyV8来运行不受信任的javascript。如何检测并杀死其中包含无限或长时间循环的javascript?我想告诉v8运行javascript并在超时时失败,如果它没有在0.1秒内完成。
答案 0 :(得分:3)
如果是python,你可以使用Interrupting cow:
from interruptingcow import timeout
try:
with timeout(5, exception=RuntimeError):
# perform a potentially very slow operation
pass
except RuntimeError:
print "didn't finish within 5 seconds"