forked from cloudflare/stpyv8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_MultiPythonThread.py
More file actions
50 lines (34 loc) · 1.07 KB
/
test_MultiPythonThread.py
File metadata and controls
50 lines (34 loc) · 1.07 KB
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
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import threading
import time
import unittest
import STPyV8
class TestMultiPythonThread(unittest.TestCase):
def testMultiPythonThread(self):
class Global:
count = 0
started = threading.Event()
finished = threading.Semaphore(0)
def sleep(self, ms):
time.sleep(ms / 1000.0)
self.count += 1
g = Global()
def run():
with STPyV8.JSIsolate():
with STPyV8.JSContext(g) as ctxt:
ctxt.eval("""
started.wait();
for (i=0; i<10; i++)
{
sleep(100);
}
finished.release();
""")
threading.Thread(target = run).start()
now = time.time()
self.assertEqual(0, g.count)
g.started.set()
g.finished.acquire()
self.assertEqual(10, g.count)
self.assertTrue((time.time() - now) >= 1)