问题
I'm using PyV8 to run untrusted javascript. How can I detect and kill javascript that has inifinite, or long running loops in it? I'd like to tell v8 to run javascript and fail with a timeout if it's not finished in 0.1 of a second.
回答1:
if it's python, you can use 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"
https://bitbucket.org/evzijst/interruptingcow
来源:https://stackoverflow.com/questions/11637075/how-do-i-prevent-malicious-javascript-in-v8-with-python