forked from cloudflare/stpyv8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_MultiJavascriptThread.py
More file actions
39 lines (28 loc) · 931 Bytes
/
test_MultiJavascriptThread.py
File metadata and controls
39 lines (28 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import threading
import unittest
import STPyV8
class TestMultiJavascriptThread(unittest.TestCase):
def testMultiJavascriptThread(self):
class Global(STPyV8.JSContext):
result = []
def add(self, value):
with STPyV8.JSUnlocker():
self.result.append(value)
g = Global()
def run():
with STPyV8.JSIsolate():
with STPyV8.JSContext(g) as ctxt:
ctxt.eval("""
for (i=0; i<10; i++)
add(i);
""")
threads = [threading.Thread(target = run),
threading.Thread(target = run)]
with STPyV8.JSLocker():
for t in threads:
t.start()
for t in threads:
t.join()
self.assertEqual(20, len(g.result))