gurobokum / pyv8

Automatically exported from code.google.com/p/pyv8
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 reported on code.google.com by melit.st...@gmail.com on 29 Apr 2013 at 6:37

GoogleCodeExporter commented 9 years ago
so, you means only auto create JSLocker in the __enter__  method? or let's you 
decide when to lock it?

Original comment by flier...@gmail.com on 30 Apr 2013 at 1:11

GoogleCodeExporter commented 9 years ago
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?

Original comment by e.generalov on 12 Jun 2013 at 9:21