eukreign / python-v8

Apache License 2.0
12 stars 6 forks source link

JSContext __exit__ does not unlock jslocker and __enter__ should lock instead of __init__ #13

Open eukreign opened 10 years ago

eukreign commented 10 years ago

From melit.st...@gmail.com on April 29, 2013 02:37:15

What steps will reproduce the problem? 1. initialize context outside of with statement

ctxt = JSContext()

lock already created and locked

with cx as ctxt: do someting ..

no unlocking because exit method never unlocks

hasattr(JSLocker, 'lock'): will always be false and lock is never released. Heres the relevant code: https://code.google.com/p/pyv8/source/browse/trunk/PyV8.py#780 Solution is to manually cll ctxt.leave()

This caused segfaults in my case.

Original issue: http://code.google.com/p/pyv8/issues/detail?id=173

eukreign commented 10 years ago

From flier...@gmail.com on April 30, 2013 06:11:24

so, you means only auto create JSLocker in the enter method? or let's you decide when to lock it?

Status: Accepted
Labels: OpSys-All

eukreign commented 10 years ago

From e.generalov on June 12, 2013 02:21:18

Surprise! Why JSContext enters the lock in the constructor? I think about too a scenario where the JSContext is created once someware, evals some javascript code and cached for future reuse.

ctx = JSContext() ctx.eval(jscode)

...

def execute(param): with JSLocker(): # Do I need it? with ctx: ctx.locals.param = param; return ctx.eval('some_function(param)')

Does it works as expected?

ps: Could I wrap the ctx with JSIsolate() instead JSLocker() in this case?