From a13176b2c80e6be4ae4f8e4bd163ba725ce296fc Mon Sep 17 00:00:00 2001 From: Jason N Date: Tue, 25 Feb 2025 11:01:13 +1100 Subject: [PATCH 1/2] Use named pipe to terminate MiniZinc on Windows Uses the same approach that the MiniZinc IDE uses to terminate MiniZinc on Windows, by writing to a named pipe created by MiniZInc. Fixes #191 --- src/minizinc/instance.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/minizinc/instance.py b/src/minizinc/instance.py index 3584452..7031716 100644 --- a/src/minizinc/instance.py +++ b/src/minizinc/instance.py @@ -661,9 +661,11 @@ async def solutions( # an unexpected Python exception occurred # First, terminate the process if sys.platform == "win32": - import signal - - proc.send_signal(signal.CTRL_C_EVENT) + with open( + f"\\\\.\\pipe\\minizinc-{proc.pid}", mode="w" + ) as named_pipe: + # Trigger MiniZinc termination + named_pipe.write("") else: proc.terminate() _ = await proc.wait() From 40635e84d5e9845d2bb79c8b9d1ece8cd0623e06 Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Tue, 25 Feb 2025 11:29:38 +1100 Subject: [PATCH 2/2] Update change log --- CHANGELOG.rst | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a09d235..523730f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,14 @@ this project adheres to `Semantic Versioning `_. Unreleased_ ------------ + +Added +^^^^^ + +- Add the ``Instance.diverse_solutions`` method to use the MiniZinc + experimental feature to model diversity and try and find a set of diverse + solutions for the given problem. + Removed ^^^^^^^ @@ -35,6 +43,8 @@ Fixed - Fix problem where some exceptions when creating processes where hidden and would then cause errors where the ``proc`` variable did not exist. +- Fix issue where MiniZinc would not correctly be terminated on Windows when + the Python process was interrupted. 0.9.0_ - 2023-04-04 ------------------- @@ -88,7 +98,7 @@ Removed - **BREAKING:** The project no longer contains the (uncompleted) direct library connection to libminizinc. With this change come some simplications in methods of relocated from ``CLIDriver`` and ``CLIInstance``, and the move of ``find_driver`` to - ``Driver.find``. + ``Driver.find``. Fixed ^^^^^ @@ -107,7 +117,7 @@ Added Fixed ^^^^^ -- Do not raise error about unsupported solver flags when MiniZinc driver would +- Do not raise error about unsupported solver flags when MiniZinc driver would not raise an error. - Fix warnings caused by unterminated coroutines when using the asynchronous iterators