Giter Site home page Giter Site logo

Comments (11)

niklasf avatar niklasf commented on May 19, 2024

This is very strange, as I hook into deepcopy to make it an alias for board.copy().

def __deepcopy__(self, memo):

Perhaps some race condition or timing issue ...

from python-chess.

LocutusOfPenguin avatar LocutusOfPenguin commented on May 19, 2024

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.

niklasf avatar niklasf commented on May 19, 2024

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.

jackalsh avatar jackalsh commented on May 19, 2024

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.

niklasf avatar niklasf commented on May 19, 2024

@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.

jackalsh avatar jackalsh commented on May 19, 2024

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.

niklasf avatar niklasf commented on May 19, 2024

Are you using board (the same object) anywhere else in that loop?

from python-chess.

jackalsh avatar jackalsh commented on May 19, 2024

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.

niklasf avatar niklasf commented on May 19, 2024

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.

jackalsh avatar jackalsh commented on May 19, 2024

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.

niklasf avatar niklasf commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.