Skip to content
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
3 changes: 2 additions & 1 deletion docs/python_interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ This does **not** control DDS's batch parallelism and is kept only for backward
compatibility. `solve_all_boards_*` already parallelize across the machine's
hardware threads automatically (via `solve_boards_n`) — the value passed here does
not size that pool. `analyse_all_plays_pbn` currently runs sequentially.
`user_threads` must be `>= 0` (`0` = auto); raises `ValueError` for negative values.
`user_threads` is ignored regardless of value (including negative values) — it
is accepted only for backward compatibility with the legacy call signature.

For per-board concurrency from Python, create one `SolverContext` per worker thread
and pass it to `solve_board` / `solve_board_pbn` (which release the GIL during the
Expand Down
4 changes: 2 additions & 2 deletions python/src/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ auto register_analysis_bindings(py::module_& module) -> void
// count argument is ignored; retained only for backward compatibility.
module.def(
"set_max_threads",
[](const int user_threads) {
[](const int /*user_threads*/) {
if (PyErr_WarnEx(
PyExc_DeprecationWarning,
"set_max_threads() is deprecated; use initialize_static_memory(). "
Expand All @@ -653,7 +653,7 @@ auto register_analysis_bindings(py::module_& module) -> void
throw py::error_already_set();
}
py::gil_scoped_release release;
SetMaxThreads(user_threads);
SetMaxThreads(0);
},
py::arg("user_threads") = 0,
"DEPRECATED: use initialize_static_memory() instead.\n\n"
Expand Down
19 changes: 18 additions & 1 deletion python/tests/test_analyse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tests for analyse_play_pbn, analyse_all_plays_pbn and dealer_par."""
"""Tests for analyse_play_pbn, analyse_all_plays_pbn, dealer_par and set_max_threads."""

import unittest

Expand Down Expand Up @@ -92,5 +92,22 @@ def test_dealer_par_invalid_vulnerability(self) -> None:
dealer_par(dd_table, dealer=0, vulnerable=9)


class TestSetMaxThreads(unittest.TestCase):
"""Tests for the deprecated set_max_threads() thread-resource hook.

user_threads is ignored regardless of value (see docs/python_interface.md);
it is accepted only for backward compatibility with the legacy call
signature, so a negative value must not be rejected.
"""

def test_negative_user_threads_is_ignored_not_rejected(self) -> None:
with self.assertWarns(DeprecationWarning):
set_max_threads(-1)

def test_emits_deprecation_warning(self) -> None:
with self.assertWarns(DeprecationWarning):
set_max_threads(0)


if __name__ == "__main__":
unittest.main()
Loading