Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (not) handling exceptions when creating processes #91

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ Changed
``timeout`` parameter is still accepted, but will add a
``DeprecationWarning`` and will be removed in future versions.

Fixed
^^^^^

- Fix problem where some exceptions when creating processes where hidden and
would then cause errors where the ``proc`` variable did not exist.

0.9.0_ - 2023-04-04
-------------------

Expand Down
6 changes: 5 additions & 1 deletion src/minizinc/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def check_result(

return True


class TimeoutError(Exception):
"""Exception raised for timeout errors (UNKNOWN status) when checking solutions"""

pass


Expand Down Expand Up @@ -102,7 +104,9 @@ def check_solution(
check = instance.solve(time_limit=time_limit)

if check.status is minizinc.Status.UNKNOWN:
raise TimeoutError(f"Solution checking failed because the checker exceeded the allotted time limit of {time_limit}")
raise TimeoutError(
f"Solution checking failed because the checker exceeded the allotted time limit of {time_limit}"
)
elif status == check.status:
return True
return check.status in [
Expand Down
14 changes: 10 additions & 4 deletions src/minizinc/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ async def solutions(
"""
# rewrite deprecated option `timeout`
if timeout is not None and time_limit is None:
warnings.warn("The usage of the `timeout` parameter is deprecated, please use the `time_limit` parameter instead.", DeprecationWarning)
warnings.warn(
"The usage of the `timeout` parameter is deprecated, please use the `time_limit` parameter instead.",
DeprecationWarning,
)
time_limit = timeout

method = self.method # Ensure self.analyse() has been executed
Expand Down Expand Up @@ -381,9 +384,9 @@ async def solutions(
# Whether the status has changed since the last `yield`
status_changed = False

# Run the MiniZinc process
proc = await self._driver._create_process(cmd, solver=solver)
try:
# Run the MiniZinc process
proc = await self._driver._create_process(cmd, solver=solver)
assert isinstance(proc.stderr, asyncio.StreamReader)
assert isinstance(proc.stdout, asyncio.StreamReader)

Expand Down Expand Up @@ -693,7 +696,10 @@ def flat(
"""
# rewrite deprecated option `timeout`
if timeout is not None and time_limit is None:
warnings.warn("The usage of the `timeout` parameter is deprecated, please use the `time_limit` parameter instead.", DeprecationWarning)
warnings.warn(
"The usage of the `timeout` parameter is deprecated, please use the `time_limit` parameter instead.",
DeprecationWarning,
)
time_limit = timeout

cmd: List[Any] = ["--compile", "--statistics"]
Expand Down
Loading