Interesting! What i know is we just can run context one by one in an isolate per thread. For example ``` const vm = require('vm'); try { // Node.js call TerminateExecution after 5 ms, then call CancelTerminateExecution and throw a timeout error vm.runInNewContext('while(1) {}', {}, { timeout: 5 }); } catch(e) { console.log(e.message); } console.log(1); vm.runInNewContext(''", {}); console.log(2); ``` Maybe you can read the source code of `node_contextify.cc` and `vm.js` in Node.js. Hope it will be helpful to you. 在2022年10月25日星期二 UTC+8 09:41:54<balu...@gmail.com> 写道:
> I also have these questions and if any v8 experts(or people with > replated knowledge/experience) see this post please give us some > information about them. > > We are embedding v8 into our HTTP server and creating one isolate > per thread, which may run multiple JavaScript scripts concurrently > (in separate contexts). > > In case scripts run too long, we use a watchdog thread to kill the > worker thread, and inside the installed signal handler, we call > isolate->TerminateExecution to stop the script. Since the isolate > is running multiple scripts, we just want to kill the one which > really timed out but preserve others(CancelTerminateExecution?). > > Is that possible to achieve? If so, what should I pay attention to? > > Any advice will be appreciated! > > -- > Jianyong Chen > > > On Thursday, January 24, 2019 at 11:29:59 PM UTC+8 crdu...@gmail.com > wrote: > >> I'm trying to understand if an how an Isolate, and the Contexts within >> the Isolate, can be used after Isolate::TerminateExecution is called. >> In v8.h, the documentation for Isolate::CancelTerminateExecution says: >> >> Resume execution capability in the given isolate, whose execution >> was previously forcefully terminated using TerminateExecution(). >> When execution is forcefully terminated using TerminateExecution(), >> the isolate can not resume execution until all JavaScript frames >> have propagated the uncatchable exception which is generated. This >> method allows the program embedding the engine to handle the >> termination event and resume execution capability, even if >> JavaScript frames remain on the stack. >> This method can be used by any thread even if that thread has not >> acquired the V8 lock with a Locker object. >> >> >> It's not clear to me what this means for the Contexts that exist within >> the Isolate at the time TerminateExecution was called. >> Does the terminate exception get raised in all Contexts within the >> Isolate? >> Does the terminate exception only get raised in the current active >> Context? >> After calling CancelTerminateExecution, can the existing Contexts still >> be used? >> >> Thanks, >> Chris >> >> -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/62313571-eaa2-472e-bee7-a9591ab692a2n%40googlegroups.com.