Skip to content

Commit 8bb8266

Browse files
author
Dejan Jovanovic
committed
add timeout parameter to check_context
1 parent b5f1cc6 commit 8bb8266

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ publish: dist
4747
python -m twine upload --repository pypi dist/*
4848

4949
install:
50-
pip install
50+
pip install .
5151

5252
clean:
5353
rm -rf *.pyc *~ __pycache__ */*.pyc */*~ */__pycache__ */*/*.pyc */*/*~ */*/__pycache_

test/context_test.py

+18
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ def test_context(self):
7575
param.dispose()
7676
ctx.dispose()
7777

78+
def test_timeout(self):
79+
cfg = Config()
80+
cfg.default_config_for_logic('QF_NIA')
81+
ctx = Context(cfg)
82+
int_t = Types.int_type()
83+
[x, y, z] = [Terms.new_uninterpreted_term(int_t, id) for id in ['x', 'y', 'z']]
84+
# x, y, z > 0
85+
for var in [x, y, z]:
86+
ctx.assert_formula(Terms.arith_gt0_atom(var))
87+
# x^3 + y^3 = z3
88+
[x3, y3, z3] = [Terms.product([var, var, var]) for var in [x, y, z]]
89+
lhs = Terms.sum([x3, y3])
90+
eq = Terms.arith_eq_atom(lhs, z3)
91+
ctx.assert_formula(eq)
92+
status = ctx.check_context(timeout=1)
93+
self.assertEqual(status, Status.INTERRUPTED)
94+
ctx.dispose()
95+
cfg.dispose()
7896

7997
if __name__ == '__main__':
8098
unittest.main()

yices/Context.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from .Status import Status
1212
from .Yices import Yices
1313

14+
import threading
15+
1416
class Context:
1517

1618
__population = 0
@@ -62,12 +64,18 @@ def assert_formulas(self, python_array_or_tuple):
6264
return True
6365

6466

65-
def check_context(self, params=None):
67+
def check_context(self, params=None, timeout=None):
6668
assert self.context is not None
67-
#unwrap the params object
69+
# unwrap the params object
6870
if params is not None:
6971
params = params.params
72+
# set the timeout
73+
if timeout is not None:
74+
timer = threading.Timer(timeout, Context.stop_search, [self])
75+
timer.start()
7076
status = Yices.check_context(self.context, params)
77+
if timeout is not None:
78+
timer.cancel()
7179
if status == -1:
7280
raise YicesException('yices_check_context')
7381
return status

0 commit comments

Comments
 (0)