PYV8 on Windows and Multi-threading crashes.

195 views
Skip to first unread message

Thomas Turner

unread,
Jul 4, 2012, 5:24:49 AM7/4/12
to py...@googlegroups.com
Hello

When I try PYV8 in windows in a multi-threaded environment it crashes.

I have attached a script to show the crash.

Please can someone else test this to see if they get the same problem or is it just me?

Tom
testcrash.py

Flier Lu

unread,
Jul 5, 2012, 1:59:05 PM7/5/12
to py...@googlegroups.com
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()


2012/7/4 Thomas Turner <ttu...@joinerysoft.com>

--
You received this message because you are subscribed to the Google Groups "PyV8" group.
To view this discussion on the web visit https://groups.google.com/d/msg/pyv8/-/aRLUzuilKlEJ.
To post to this group, send email to py...@googlegroups.com.
To unsubscribe from this group, send email to pyv8+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyv8?hl=en.

Reply all
Reply to author
Forward
0 new messages