rename async keyword in python API
authorRoland Kaminski <kaminski@cs.uni-potsdam.de>
Sat, 3 Nov 2018 21:34:57 +0000 (22:34 +0100)
committerPeter Michael Green <plugwash@raspbian.org>
Thu, 14 Mar 2019 17:34:56 +0000 (17:34 +0000)
Bug-Debian: https://bugs.debian.org/912552
Forwarded: https://github.com/potassco/clingo/pull/125

`async` is a reserved keyword starting with python 3.7:
https://docs.python.org/3/whatsnew/3.7.html#summary-release-highlights

The `Control` class method `solve()` now uses the following keyword
argument list:

```
solve(self, assumptions, on_model, on_finish, yield_, async_)

```

closes #125

Gbp-Pq: Name gringo-python37-async.patch

app/clingo/tests/python/assumptions4.lp
app/clingo/tests/python/cancel.lp
app/clingo/tests/python/interrupt.lp
app/clingo/tests/python/test.lp
app/clingo/tests/run.py
examples/clingo/controller-async/controller.py
examples/clingo/controller-processes/client.py
examples/clingo/controller-threads/controller.py
examples/clingo/robots/visualize.py
examples/clingo/solve-async/solve-async-py.lp
libpyclingo/pyclingo.cc

index d5496b6773c79d4bcd8a5c9da5f33a10415a40c1..37122068133825d27cbe0ffbde71fda555222524 100644 (file)
@@ -7,7 +7,7 @@ def main(prg):
     prg.ground([("base", [])])
     prg.solve(assumptions=[(Function("a"), True)])
 
-    with prg.solve(assumptions=[(Function("a"), True)], async=True) as handle:
+    with prg.solve(assumptions=[(Function("a"), True)], async_=True) as handle:
         handle.get()
 
     with prg.solve(assumptions=[(Function("a"), True)], yield_=True) as handle:
index 97ca50208acc08cbc36ff9cf0d11163a42124738..7ef4491def242b1d9a60165ce5ec9ec26667ed7b 100644 (file)
@@ -8,7 +8,7 @@ def main(prg):
         prg.assign_external(clingo.Function("p"), True)
         prg.solve()
         prg.assign_external(clingo.Function("p"), False)
-        with prg.solve(async=True) as handle:
+        with prg.solve(async_=True) as handle:
             handle.wait(0.01)
             handle.cancel()
 
index 15f99c849adf59a737ea029de08971b11ea56cb7..993ffe8cb83cfa18383d3ed328325d3a76cdd436 100644 (file)
@@ -8,7 +8,7 @@ def main(prg):
         prg.assign_external(clingo.Function("p"), True)
         prg.solve()
         prg.assign_external(clingo.Function("p"), False)
-        with prg.solve(async=True) as handle:
+        with prg.solve(async_=True) as handle:
             handle.wait(0.01)
             prg.interrupt()
 
index 233b19302e34f1ed9f0af18694b20e18604c8447..d5c68980e2b561948cf283fa95f6eefa67edfc75 100644 (file)
@@ -31,7 +31,7 @@ def main (prg):
         parts.append(("cumulative", [i]))
         prg.ground(parts)
         parts = []
-        with prg.solve(on_model=on_model, on_finish=on_finish, async=True) as handle:
+        with prg.solve(on_model=on_model, on_finish=on_finish, async_=True) as handle:
             handle.wait(0)
             ret = handle.get()
         writeln("Answer: 42")
index 7da85a1a432690adc6e28d4f119a7a0156ca2278..bf22e13ae28215ed106953e4b6647a5dbf70ca1a 100755 (executable)
@@ -136,7 +136,7 @@ if parse_ret.action == "run":
                 inst = open(b + ".lp", 'rU', encoding='utf-8').read()
                 if (not with_python and re.search(r"#script[ ]*\(python\)", inst)) or \
                    (not with_lua and re.search(r"#script[ ]*\(lua\)", inst)) or \
-                   (not with_threads and re.search("async=", inst)) or \
+                   (not with_threads and re.search("async_=", inst)) or \
                    (not with_threads and re.search("solve_async", inst)):
                     continue
 
index d8568b06758bd22992a0748b3ab854d08058a728..b2cbc2e940b808287b196e0dd41aedac9cf53e19 100755 (executable)
@@ -104,7 +104,7 @@ class Solver:
             self.prg.ground([("sleep", [self.k])])
             self.prg.release_external(clingo.Function("sleep", [self.k-1]))
             self.prg.assign_external(clingo.Function("sleep", [self.k]), True)
-        self.future = self.prg.solve(on_model=self.on_model, on_finish=on_finish, async=True)
+        self.future = self.prg.solve(on_model=self.on_model, on_finish=on_finish, async_=True)
 
     def stop(self):
         self.future.cancel()
index 1d73bbc2320d2c5651009c644d44d25d399d0522..7b707f27ed9c7b36d6e05bd303e0c120b21b4b12 100644 (file)
@@ -42,7 +42,7 @@ def main(prg):
             if state == States.SOLVE:
                 f = prg.solve(
                     on_model  = lambda model: conn.sendall(b"Answer: " + str(model).encode() + b"\n"),
-                    on_finish = lambda ret:   conn.sendall(b"finish:" + str(ret).encode() + (b":INTERRUPTED" if ret.interrupted else b"") + b"\n"), async=True)
+                    on_finish = lambda ret:   conn.sendall(b"finish:" + str(ret).encode() + (b":INTERRUPTED" if ret.interrupted else b"") + b"\n"), async_=True)
             msg = recv.readline().decode()
             if state == States.SOLVE:
                 f.cancel()
index df5a6e307376f9c3c70d71bfb7132ee36a0ea2fc..64ff059d52dacf54f59fe69d4894e211d09f8c38 100755 (executable)
@@ -129,7 +129,7 @@ class SolveThread(Thread):
     def run(self):
         while True:
             if self.state == SolveThread.STATE_SOLVE:
-                f = self.prg.solve(on_model=self.on_model, on_finish=self.on_finish, async=True)
+                f = self.prg.solve(on_model=self.on_model, on_finish=self.on_finish, async_=True)
             msg = self.input.receive()
             if self.state == SolveThread.STATE_SOLVE:
                 f.cancel()
index 2cc24da7f507ba108f2874a896cbc94f1b0f7295..a105c94a8cc7cf322bc9804698a5732915d1fa57 100755 (executable)
@@ -119,7 +119,7 @@ class Solver:
         for x in self.__assign:
             self.__prg.assign_external(x, True)
         self.__solution = None
-        self.__future = self.__prg.solve(on_model=self.__on_model, async=True)
+        self.__future = self.__prg.solve(on_model=self.__on_model, async_=True)
 
     def busy(self):
         if self.__future is None:
@@ -127,7 +127,7 @@ class Solver:
         if self.__future.wait(0):
             if self.__solution is None:
                 self.__next()
-                self.__future = self.__prg.solve(on_model=self.__on_model, async=True)
+                self.__future = self.__prg.solve(on_model=self.__on_model, async_=True)
                 return True
             else:
                 self.__future = None
index 6cd9a2d954a958f7eb858066fda571a3bc16d34e..4573c50f5be134d6f51f833a41e298ca81e1d713 100644 (file)
@@ -10,7 +10,7 @@ def make_on_finish(stop):
 def main(prg):
     stop = [False]
     prg.ground([("base", [])])
-    future, n, m = prg.solve(on_finish=make_on_finish(stop), async=True), 0, 0
+    future, n, m = prg.solve(on_finish=make_on_finish(stop), async_=True), 0, 0
     while not stop[0]:
         x, y, m = random(), random(), m+1
         if x * x + y * y < 1: n+= 1
index 73b2f1a80fa0983142422ae01feda9800967c8dd..39effee86a973887a382486b2870e34abd41e578 100644 (file)
@@ -6302,22 +6302,23 @@ active; you must not call any member function during search.)";
         CHECK_BLOCKED("solve");
         Py_XDECREF(stats);
         stats = nullptr;
-        static char const *kwlist[] = {"assumptions", "on_model", "on_statistics", "on_finish", "yield_", "async", nullptr};
-        Reference pyAss = Py_None, pyM = Py_None, pyS = Py_None, pyF = Py_None, pyYield = Py_False, pyAsync = Py_False;
-        ParseTupleAndKeywords(args, kwds, "|OOOOOO", kwlist, pyAss, pyM, pyS, pyF, pyYield, pyAsync);
+        static char const *kwlist[] = {"assumptions", "on_model", "on_statistics", "on_finish", "yield_", "async", "async_", nullptr};
+        Reference pyAss = Py_None, pyM = Py_None, pyS = Py_None, pyF = Py_None, pyYield = Py_False, pyAsync = Py_False, pyAsync_ = Py_False;
+        ParseTupleAndKeywords(args, kwds, "|OOOOOOO", kwlist, pyAss, pyM, pyS, pyF, pyYield, pyAsync, pyAsync_);
         std::vector<clingo_literal_t> ass;
         if (!pyAss.is_none()) {
             clingo_symbolic_atoms_t *atoms;
             handle_c_error(clingo_control_symbolic_atoms(ctl, &atoms));
             ass = pyToLits(pyAss, atoms, false, false);
         }
+        bool async = pyAsync.isTrue() || pyAsync_.isTrue();
         clingo_solve_mode_bitset_t mode = 0;
         if (pyYield.isTrue()) { mode |= clingo_solve_mode_yield; }
-        if (pyAsync.isTrue()) { mode |= clingo_solve_mode_async; }
+        if (async) { mode |= clingo_solve_mode_async; }
         auto handle = SolveHandle::construct();
         auto notify = handle->notify(&SolveHandle::on_event, pyM, pyS, pyF);
         doUnblocked([&](){ handle_c_error(clingo_control_solve(ctl, mode, ass.data(), ass.size(), notify, handle.obj, &handle->handle)); });
-        if (!pyYield.isTrue() && !pyAsync.isTrue()) { return handle->get(); }
+        if (!pyYield.isTrue() && !async) { return handle->get(); }
         else { return handle; }
     }
     Object cleanup() {
@@ -6551,7 +6552,7 @@ Arguments:
 path -- path to program)"},
     // solve
     {"solve", to_function<&ControlWrap::solve>(), METH_KEYWORDS | METH_VARARGS,
-R"(solve(self, assumptions, on_model, on_finish, yield_, async) -> SolveHandle|SolveResult
+R"(solve(self, assumptions, on_model, on_finish, yield_, async_) -> SolveHandle|SolveResult
 
 Starts a search.
 
@@ -6573,10 +6574,10 @@ assumptions   -- List of (atom, boolean) tuples or program literals that serve
                  (Default: [])
 yield_        -- The resulting SolveHandle is iterable yielding Model objects.
                  (Default: False)
-async         -- The solve call and SolveHandle.resume() are non-blocking.
+async_        -- The solve call and SolveHandle.resume() are non-blocking.
                  (Default: False)
 
-If neither yield_ nor async is set, the function returns a SolveResult right
+If neither yield_ nor async_ is set, the function returns a SolveResult right
 away.
 
 Note that in gringo or in clingo with lparse or text output enabled this
@@ -6635,7 +6636,7 @@ def on_finish(res, canceled):
 def main(prg):
     prg.add("p", [], "{a;b;c}.")
     prg.ground([("base", [])])
-    with prg.solve(on_model=on_model, on_finish=on_finish, async=True) as handle:
+    with prg.solve(on_model=on_model, on_finish=on_finish, async_=True) as handle:
         while not handle.wait(0):
             # do something asynchronously
         print(handle.get())