Added timeout argument to limit javascript function call time#4
Added timeout argument to limit javascript function call time#4desertkun wants to merge 2 commits intobuffer:masterfrom
Conversation
|
Added also a timeout to try:
context.eval(text, "", -1, -1, None, 500L)
except JSTimeoutError:
raise RuntimeError("Evaluation timeout!") |
|
The patch sounds good to me but would like to get a feedback from @flier. Moreover I highly suggest to send PR against this repo https://github.com/flier/pyv8. This repo is just a fork I created for Thug (https://github.com/buffer/thug) but it is not intended to be the official one. Thanks! |
|
Thanks for pointing it out. FYI I am currently contributing to this new project and I invite you to do the same. PyV8 can be considered a dead project because of the lack of any support from the original author. IMHO investing time and efforts on it is worthless at this point . |
|
@buffer looks good, does it have threading support? Is it production ready? |
|
The code base is already extremely good and it should be thread-safe. I am going to send some PRs to add some features I need for Thug in the next days. But that's just minor stuff. |
So recently I faced the problem that there's no way to limit function call time in any way.
For example, if you run this simple javascript code from python:
You will end up with infinite loop indeed, with no way exit that from python code, except kill the whole process.
That patch affects only
applymethod of javascript function object so it now has such signature:And the code that can handle call 500ms timeout:
Under the hood, it uses
SIGALRMandv8::V8::TerminateExecutionto kill the running code gracefully.Why don't just use
SIGALRMon python side? Python cannot catchSIGALRMwhileCcode is executing.