Google v8 engine doesn't support the thread safe executing, but it provide some lock to run javascript in different threads one by one.
It means if our script want to use v8 in multiple thread, we must lock the current thread before execute script
For your example, you could use `with PyV8.JSLocker():` to lock the main thread before all the thread started, and we could create a JSContext which will automatic detect the lock mode, and lock the thread when it is executing javascript. If you sure the thread will not execute any javascript, you could use `with JSUnlocker():` to release the v8 engine for other thread. Please check the test case TestMultithread in PyV8.py for more detail.
class testit(Thread):
def __init__ (self,n):
Thread.__init__(self)
self.n = n
def run(self):
time.sleep(random.randint(1, 10))
with PyV8.JSContext() as ctxt:
val = ctxt.eval(self.n)
print "%s = %s" % (self.n,val)
with PyV8.JSLocker():
for n in range(0,255):
js = "%d + 10" % (n)
current = testit(js)
current.start()