Comments (11)
This is very strange, as I hook into deepcopy to make it an alias for board.copy()
.
python-chess/chess/__init__.py
Line 3495 in e5dee27
Perhaps some race condition or timing issue ...
from python-chess.
in think() from picochess.py:
If its "engine.position(game.copy())"
I crushing with lots(!) of error messages like so:
2015-09-09 11:59:48.443 ERROR uci - _info: exception parsing pv
Traceback (most recent call last):
File "./libs/chess/uci.py", line 715, in _info
pv.append(board.push_uci(token))
File "./libs/chess/init.py", line 2357, in push_uci
move = self.parse_uci(uci)
File "./libs/chess/init.py", line 2344, in parse_uci
raise ValueError("illegal uci: {0} in {1}".format(repr(uci), self.fen()))
ValueError: illegal uci: 'e4d5' in rnbqkbnr/1pp2ppp/8/p2pP3/P7/8/1PPPPPPP/RNBQKBNR w KQkq d6 0 3
If its "engine.position(copy.deepcopy(game))"
no problem...working.
We had this problem already, at the beginning of your uci-new-engine rewrite. The solution been, to give a copy of game inside the engine. Somehow, copy() not working like the python version.
If y want, y can try out yrsf:
picochess.py -e engines/stockfish
a2a4
a7a5 (from book)
a1a2
(starts thinking, and crushing)
from python-chess.
This is definitely just a difference in timing.
>>> import chess
>>> import copy
>>> b = chess.Board()
>>> b.marker = object()
>>> c = copy.deepcopy(b)
>>> c.marker # Verify that deepcopy just hooks into Board.copy()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Board' object has no attribute 'marker'
I'll keep this issue open as reminder for looking into thread safe boards.
from python-chess.
I believe this issue is not solved. Looking for workaround for more than a week.
In my case I use several processes, not threads, independetly searching for a mates. Positions taken from database. Deep copy as you suggest it not helps.
from python-chess.
@jackalsh: The UCI interface is not thread-safe. You'll have to ensure the board is not modified until engine.position()
returns. When calling asynchronously this is fast and happens before any IO is made.
If it still doesn't work, a minimal reproducible example would be helpful.
I didn't suggest to use deepcopy (as it does not reliably solve thread-safety issues), but at least there should be no functional difference between board.copy()
and copy.deepcopy(board)
.
from python-chess.
I found some workaround, which is enough for me.
The solution is set a 50 ms timer in cycle.
I am not giving you full code, because it is long, but a short version.
https://gist.github.com/jackalsh/00c68e618c560b472f72
This works like a magic on 2 million positions till now.
from python-chess.
Are you using board
(the same object) anywhere else in that loop?
from python-chess.
Indeed, yes, I have something like
print("(%s/%s) %s: Mate in %s - %s" % (index, limit, blunder_id, mate, board.fen()))
at the end of the cycle, but I don't think this caused the problem. I removed this code during the tests, it did'nt help.
from python-chess.
Yeah, I was looking for writing code. board.fen()
should be completely read-only. If this is the case, then we indeed have a bug, here.
from python-chess.
Its not as simple, because we use database as a backend for the script. Code itself will not be as useful. If you want, I will send you a code, but there is nothing special in it.
Just querying database for positions, looping over them and calling engine to calculate the score and pv.
I first tried use PyCharm's debuger to catch the bug, but it never fail. Probably because of debuger's internal delays or something. When I use one instance of the script, it also not fail (or I just did'nt wait enough). When I use several instances in parallel, they crash at the random time within first few minutes. This is strange, because there are nothing should be shared between the processes and working with database(PostgreSQL), I believe, is thread-safe
from python-chess.
With one year worth of changes and me being unable to reproduce this (from the start), it's probably best to make a new issue if this problem persists.
from python-chess.
Related Issues (20)
- Test chess.engine under Cygwin
- "info string" on startup causes assertion HOT 2
- chess.pgn.GameNode add_line() creates duplicate variations HOT 1
- Documentation incorrect for chess.Board.turn HOT 1
- board.mirror() HOT 1
- flipping the board HOT 1
- is_variant_draw seems not to work properly HOT 1
- getting `chess.IllegalMoveError` despite the fact that move is legal HOT 5
- always castling rights for clean_castling_rights()
- Incorrect perft(4) with Kiwipete. HOT 3
- impossible to get the moves in san format after pushing the move
- [feature request] add `board.san_move_stack` similar to `board.move_stack` to get san format moves HOT 1
- Is this expected or simply a bug? HOT 1
- Using limit(mate=mate) terminates search before mate HOT 3
- Exception in callback Protocol._line_received('') HOT 1
- CancelledError and TimeoutError when using multithreaded Stockfish to analyze certain sequence of board positions. HOT 1
- Feature request: new argument for chess.svg.board() HOT 1
- engine.analyse() exits with TimeoutError exception HOT 2
- Parsing a database with `read_game` results in roughly 2 extra results per game
- `illegal san` error message when the first game in a database contains a move in the White or Black header HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-chess.