Closed desertkun closed 6 years ago
I like this interface better:
with v8py.timeout(1.0):
ctx.glob.freeze()
This leaves the possibility open for keyword arguments to a JavaScript function to do something like creating an object and passing that as an argument.
Well, current implementation of __call__
has no **kwargs
processing whatsoever, because all arguments that go to javascript are passed via *args
. Also, it would be really nice to keep api consistent to the eval(..., timeout=1.0)
call.
I agree about using with
statement, but
timeout
argument from eval
. That would break compatibility for some users.timeout
has much of sense in context of single javascript call, so using with
here is a little bit of overkillwith
and suddenly breaker_thread
kicks in and interrupts javascript execution?Yes, __call__
currently doesn't use kwargs, but I want to leave the possibility open.
It would be reasonable to remove the timeout argument from eval, but I have no idea if anything is dependent on it. At least, it wouldn't be hard for those users to fix it.
with
is arguably overkill, but I can't think of a better way. Plus you might want to run multiple JavaScript things with one timeout. (Maybe.)
The implementation would just be __enter__
starting a thread, __exit__
canceling it, and the thread doing isolate->TerminateExecution()
after a timeout. TerminateExecution
doesn't do anything if there is no JavaScript currently running.
Closed as bad API design.
JSFunction
's__call__
method lacks the timeout functionality likeeval
has.Calling
freeze
method will hang python for good:This pull request solves the issue like
eval
, adding optionaltimeout
argument to **kwargs: