Skip to content

Conversation

@desertkun
Copy link

@desertkun desertkun commented May 4, 2017

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:

while(true);

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 apply method of javascript function object so it now has such signature:

apply(this, args = [], kwargs = {}, timeout = 0)

And the code that can handle call 500ms timeout:

try:
    some_function.apply(some_function, [], {}, 500L)
except JSTimeoutError:
    raise RuntimeError("Function call timeout!")

Under the hood, it uses SIGALRM and v8::V8::TerminateExecution to kill the running code gracefully.

Why don't just use SIGALRM on python side? Python cannot catch SIGALRM while C code is executing.

@desertkun
Copy link
Author

Added also a timeout to context.eval:

try:
    context.eval(text, "", -1, -1, None, 500L)
except JSTimeoutError:
    raise RuntimeError("Evaluation timeout!")

@buffer
Copy link
Owner

buffer commented May 11, 2017

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!

@buffer buffer self-assigned this May 11, 2017
@desertkun
Copy link
Author

@buffer as you don't have issues here I'd like also to mention that there's a serious issues with threading here, static doesn't go well when you create object template in one thread (isolate) and then use it in another. See the fix.

Did not create issue at flier's repo as it's obviously dead.

@buffer
Copy link
Owner

buffer commented Jun 29, 2017

Thanks for pointing it out. FYI I am currently contributing to this new project

https://github.com/tbodt/v8py

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 .

@desertkun
Copy link
Author

@buffer looks good, does it have threading support? Is it production ready?

@buffer
Copy link
Owner

buffer commented Jun 29, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants