-
Notifications
You must be signed in to change notification settings - Fork 457
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
Restart engine when bot exceeds per-move time limit #896
Conversation
The python-chess SimpleEngine class is meant to be used as a context manager, so make use of its __enter__() and __exit__() methods to ensure complete startup and shutdown. Also, if the engine is shutting down due to an exception, do not attempt any more communication (i.e., ping and quit).
Since EngineWrapper automatically closes the engine when exiting from the engine context in play_game(), catching the TimeoutError is no longer necessary. If the engine goes way beyond time controls, it is probably in an error state and can only benefit from restarting.
The new test uses a rudimentary engine (buggy_engine.py) that only plays moves to let black win with a scholars mate. However, on the third move, it pauses long enough for the python-chess library to intervene and raise an asyncio.TimeoutError exception. In a successful test, the engine restarts and finishes the game. Also, add an optional variable for a text log file to collect useful data during tests. See testing_log_file_name on line 88.
To see the changes to test_bot/test_bot.py, hide the whitespace changes. Since the buggy_engine made for the new test can only play a set list of moves, I had to change the |
test_bot/test_bot.py
Outdated
|
||
@pytest.mark.timeout(30, method="thread") | ||
def test_buggy_engine() -> None: | ||
"""Test lichess-bot with Stockfish (UCI).""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring should be changed since we don't use stockfish.
lichess-bot plays black so it always receieves an odd number of moves, so the engine that waits for 11 seconds is the outside engine and not the one managed by lichess-bot. You can change
and line 346 in |
I'm going to fix this PR so the git blame for test_bot.py isn't rendered completely useless. I think my editor changed the newlines on every line. |
This PR is replaced by #897 to reduce clutter due to whitespace issues. |
Type of pull request:
Description:
If a user specifies a per-move time limit in their configuration file--e.g.,
uci_options: go_commands: movetime: 1000
for 1000 milliseconds per move--and the engine exceeds this time limit by more than 10 seconds, the python-chess library will intervene and cancel the search while raising aTimeoutError
. Previously, this error would be caught and mainplay_game()
loop would carry on without sending a move to lichess.org.Now, the
TimeoutError
is propagated until it hits thebackoff
decoration ofplay_game()
. This shuts down the engine (correctly, now, due to changes in engine_wrapper.py) and restarts it whenbackoff
restartsplay_game()
. Even if the engine keeps exhibiting the same buggy behavior, the errors will be displayed on the terminal and log, so the user will know that something is wrong.Related Issues:
This PR closes #893 and should be a better solution to #623 than the previous PR #628.
Checklist: