Mercurial > pymonkey
comparison test_pymonkey.py @ 66:b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 26 Jul 2009 15:06:19 -0700 |
parents | fb7e11dec538 |
children | 9b3f4e53e365 |
comparison
equal
deleted
inserted
replaced
65:f89a582c1276 | 66:b49180c39d0a |
---|---|
1 import sys | 1 import sys |
2 import unittest | 2 import unittest |
3 import weakref | 3 import weakref |
4 import time | |
5 import threading | |
4 | 6 |
5 import pymonkey | 7 import pymonkey |
6 | 8 |
7 class PymonkeyTests(unittest.TestCase): | 9 class PymonkeyTests(unittest.TestCase): |
8 def _evaljs(self, code): | 10 def _evaljs(self, code): |
36 cx = pymonkey.Runtime().new_context() | 38 cx = pymonkey.Runtime().new_context() |
37 cx.set_operation_callback(opcb) | 39 cx.set_operation_callback(opcb) |
38 obj = cx.new_object() | 40 obj = cx.new_object() |
39 cx.init_standard_classes(obj) | 41 cx.init_standard_classes(obj) |
40 | 42 |
41 # TODO: This isn't a very good test; we need to actually | 43 def watchdog(): |
42 # set up a signal or launch a separate thread to call | 44 time.sleep(0.1) |
43 # this method as though it were a watchdog to limit the | 45 cx.trigger_operation_callback() |
44 # amount of time the JS can run. However, Pymonkey doesn't | 46 |
45 # yet handle the GIL properly so this isn't possible. | 47 thread = threading.Thread(target = watchdog) |
46 cx.trigger_operation_callback() | 48 thread.start() |
47 | 49 |
48 self.assertRaises( | 50 self.assertRaises( |
49 pymonkey.error, | 51 pymonkey.error, |
50 cx.evaluate_script, | 52 cx.evaluate_script, |
51 obj, 'while (1) {}', '<string>', 1 | 53 obj, 'while (1) {}', '<string>', 1 |