python-chess icon indicating copy to clipboard operation
python-chess copied to clipboard

Exception in callback Protocol._line_received('')

Open IceboxDev opened this issue 1 year ago • 1 comments

I'm experiencing an AssertionError when trying to analyze a chess board using Chessify UCI chess engine. The error occurs after the analysis is completed and seems to be related to the internal state management of engine communication.


Minimal code to reproduce:

import chess.engine
import constants

engine = chess.engine.SimpleEngine.popen_uci(constants.ENGINE_PATH)

board = chess.Board()
result = engine.analyse(board, chess.engine.Limit(depth=30))
print(result)

Stacktrace:

Exception in callback Protocol._line_received('')
handle: <Handle Protocol._line_received('')>
Traceback (most recent call last):
  File "C:\Users\Manta\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "E:\Projects\UniversalChessTool\.venv\lib\site-packages\chess\engine.py", line 1093, in _line_received
    self.command._line_received(self, line)
  File "E:\Projects\UniversalChessTool\.venv\lib\site-packages\chess\engine.py", line 1385, in _line_received
    assert self.state in [CommandState.ACTIVE, CommandState.CANCELLING]
AssertionError
  • self.state has value CommandState.DONE

result:

result = {
    'string': 'NNUE evaluation using nn-b1a57edbea57.nnue',
    'depth': 30,
    'seldepth': 48,
    'multipv': 1,
    'score': 'PovScore(Cp(+32), WHITE)',
    'nodes': 123673136,
    'nps': 9619876,
    'hashfull': 140,
    'tbhits': 0,
    'time': 12.856,
    'pv': [
        'Move.from_uci(e2e4)', 'Move.from_uci(e7e5)', 'Move.from_uci(g1f3)', 'Move.from_uci(b8c6)',
        'Move.from_uci(f1b5)', 'Move.from_uci(g8f6)', 'Move.from_uci(e1g1)', 'Move.from_uci(f6e4)',
        'Move.from_uci(f1e1)', 'Move.from_uci(e4d6)', 'Move.from_uci(f3e5)', 'Move.from_uci(f8e7)',
        'Move.from_uci(b5f1)', 'Move.from_uci(c6e5)', 'Move.from_uci(e1e5)', 'Move.from_uci(e8g8)',
        'Move.from_uci(d2d4)', 'Move.from_uci(e7f6)', 'Move.from_uci(e5e1)', 'Move.from_uci(d6f5)',
        'Move.from_uci(c2c3)', 'Move.from_uci(d7d5)', 'Move.from_uci(b1d2)', 'Move.from_uci(f5d6)',
        'Move.from_uci(a2a4)', 'Move.from_uci(a7a5)', 'Move.from_uci(d2f3)', 'Move.from_uci(c8f5)',
        'Move.from_uci(h2h3)', 'Move.from_uci(f5e4)', 'Move.from_uci(c1f4)', 'Move.from_uci(c7c6)',
        'Move.from_uci(f3e5)', 'Move.from_uci(f8e8)', 'Move.from_uci(f4h2)', 'Move.from_uci(e4f5)',
        'Move.from_uci(d1b3)', 'Move.from_uci(h7h5)', 'Move.from_uci(e1e2)', 'Move.from_uci(g7g6)',
        'Move.from_uci(a1e1)', 'Move.from_uci(h5h4)', 'Move.from_uci(e5g4)', 'Move.from_uci(f5g4)',
        'Move.from_uci(e2e8)', 'Move.from_uci(d6e8)', 'Move.from_uci(h3g4)'
    ],
    'currmove': 'Move.from_uci(h2h4)',
    'currmovenumber': 20
}

Expected Behavior: The analysis should complete without any errors, and the engine should return the analysis results.


Environment: Python version: 3.10 python-chess version: 1.10 Operating System: Windows 10 Chess Engine Used: ChessifyClientStockfish

Additional Context: The issue occurs consistently with the above setup. The analysis result is correct; the issue seems to be purely related to internal state handling in the python-chess library.

IceboxDev avatar Mar 13 '24 02:03 IceboxDev

Thanks for the detailed report. Can you please also enable debug logging and include the output?

niklasf avatar Mar 13 '24 21:03 niklasf

I attempted a blind fix ... please reopen with the requested details if this didn't help.

niklasf avatar Jul 31 '24 20:07 niklasf