Skip to content

Conversation

@vdbergh
Copy link
Contributor

@vdbergh vdbergh commented Apr 28, 2025

Some advantages:

(1) The Python logging framework is is thread safe so we do not have to worry about printing from different threads.

(2) The Python logging framework is very configurable which may be useful in the future.

This implementation is very rudimentary since I want to make sure that other people also agree that this is a good thing to do.

I have drafted this since it is a RFC.

@vdbergh vdbergh marked this pull request as draft April 28, 2025 13:33
@robertnurnberg
Copy link
Contributor

I may be useful to see a comparison between old and new output? We could also take the chance to consistently change to usage of f-strings?

By the way, completely unrelated: since official-stockfish/books#52 we have SRI checksums for all the books. So we can check the integrity of local books when deciding whether to download books from the repo. I think you know that part of the worker code best, in case you want to give it a try.

@vdbergh
Copy link
Contributor Author

vdbergh commented May 4, 2025

I may be useful to see a comparison between old and new output? We could also take the chance to consistently change to usage of f-strings?

It does not look particularly nice now but it can be further refined.

I think for the console logger we should suppress the INFO:worker and INFO:games prompts. I would keep the WARNING:
and ERROR: prompts though.

For the file logger (not implemented now) we could add time stamps.

vdbergh@pl:~/fishtest/worker$ python worker.py

______ _     _     _            _                        _
|  ___(_)   | |   | |          | |                      | |
| |_   _ ___| |__ | |_ ___  ___| |_  __      _____  _ __| | _____ _ __
|  _| | / __| '_ \| __/ _ \/ __| __| \ \ /\ / / _ \| '__| |/ / _ \ '__|
| |   | \__ \ | | | ||  __/\__ \ |_   \ V  V / (_) | |  |   <  __/ |
\_|   |_|___/_| |_|\__\___||___/\__|   \_/\_/ \___/|_|  |_|\_\___|_|

INFO:worker:Worker started in /home/vdbergh/fishtest/worker with PID=676571
INFO:worker:Found g++ version 13.3.0
INFO:worker:No clang++ or clang++ is not executable
INFO:worker:machine_id 38370896c30440658170914419b6756c obtained from /etc/machine-id
INFO:worker:Default uuid_prefix: 3b14e644
INFO:worker:Worker version 276 connecting to https://tests.stockfishchess.org:443
INFO:worker:Confirming cached credentials with https://tests.stockfishchess.org:443
INFO:worker:Credentials ok!
INFO:worker:System memory determined to be: 15.308GiB
INFO:worker:Worker constraints: {'concurrency': 1, 'max_memory': 7838, 'min_threads': 1}
INFO:worker:Config file /home/vdbergh/fishtest/worker/fishtest.cfg written
INFO:worker:Writing sri hashes to /home/vdbergh/fishtest/worker/sri.txt
INFO:worker:Verify worker version...
INFO:games:Post request https://tests.stockfishchess.org:443/api/request_version handled in 85.44ms (server: 0.26ms)
INFO:worker:Using g++ 13.3.0
INFO:worker:Toolchain check...
INFO:worker:Obtaining version info for /home/vdbergh/fishtest/worker/testing/fastchess...
INFO:worker:Found fastchess alpha 1.2.0 01010101-f8e58066
INFO:games:Downloading https://raw.githubusercontent.com/official-stockfish/fishtest/master/worker/sri.txt
WARNING:worker:worker.py has been modified!
WARNING:worker:games.py has been modified!
WARNING:worker:This worker is tainted...
INFO:worker:UUID: 3b14e644-bd74-46bb-b05b-86a5f25d8309
INFO:worker:Start heartbeat
INFO:worker:Current time is 2025-05-04 07:38:14.259749+00:00 UTC (local offset: +02:00) 
INFO:worker:Verify worker version...
INFO:games:Post request https://tests.stockfishchess.org:443/api/request_version handled in 93.03ms (server: 0.31ms)
INFO:worker:Remaining number of GitHub api calls = 5000
INFO:worker:Fetching task...
INFO:games:Post request https://tests.stockfishchess.org:443/api/request_task handled in 76.58ms (server: 4.04ms)
INFO:worker:Working on task 723 from https://tests.stockfishchess.org:443/tests/view/68109e2c3629b02d74b166ee
INFO:worker:Running cntst6 vs master
INFO:games:Variable task sizes used. Opening offset = 61542
INFO:games:Downloading https://api.github.com/repos/FauziAkram/Stockfish/zipball/afc3c6080a403f9bb2db469d2149b193c5ab19f7
INFO:games:Build uses default net: nn-1c0000000000.nnue
INFO:games:Build uses default net: nn-37f18f62d772.nnue
INFO:games:Using native target architecture
Existing nn-1c0000000000.nnue validated, skipping download
Existing nn-37f18f62d772.nnue validated, skipping download

Config:
debug: 'no'
sanitize: 'none'
optimize: 'yes'
arch: 'x86_64'
bits: '64'

@vdbergh
Copy link
Contributor Author

vdbergh commented May 4, 2025

By the way, completely unrelated: since official-stockfish/books#52 we have SRI checksums for all the books. So we can check the integrity of local books when deciding whether to download books from the repo. I think you know that part of the worker code best, in case you want to give it a try.

I guess the idea is that the books in the book repo can be updated without changing their name. Correct?

@vdbergh
Copy link
Contributor Author

vdbergh commented May 4, 2025

By the way, completely unrelated: since official-stockfish/books#52 we have SRI checksums for all the books. So we can check the integrity of local books when deciding whether to download books from the repo. I think you know that part of the worker code best, in case you want to give it a try.

I guess the idea is that the books in the book repo can be updated without changing their name. Correct?

BTW is this metadata kept up to date automatically?

@robertnurnberg
Copy link
Contributor

Yes, the metadata will be kept up to date from now on. (In the same way that the Sri data for the fishtest worker is kept up to date: manually within each PR).

I think we'll still use new versions for new books. But yes, for things like adding missing move numbers (without changing the exits and their order), we can now use the Sri to trigger a book update on the worker.

The main reason for the new meta data was to ensure the book data does not corrupted locally over time. We take great care to avoid duplicate book exits etc, so it would be a shame if a small edit in a local book copy invalidates that.

@vdbergh
Copy link
Contributor Author

vdbergh commented May 4, 2025

Yes, the metadata will be kept up to date from now on. (In the same way that the Sri data for the fishtest worker is kept up to date: manually within each PR).

For the worker it is checked by CI. I was wondering if at least something like this was in place for the books.

I think we'll still use new versions for new books. But yes, for things like adding missing move numbers (without changing the exits and their order), we can now use the Sri to trigger a book update on the worker.

The main reason for the new meta data was to ensure the book data does not corrupted locally over time. We take great care to avoid duplicate book exits etc, so it would be a shame if a small edit in a local book copy invalidates that.

Ok I understand. Of course people are not supposed to edit files in the testing folder, but who knows what some people might do...

@robertnurnberg
Copy link
Contributor

It's not checked within the ci yet. But I can look into setting that up.

@vdbergh
Copy link
Contributor Author

vdbergh commented May 4, 2025

It's not checked within the ci yet. But I can look into setting that up.

I think it would be a good idea. In my experience people do not keep metadata/documentation up to date unless it is enforced in some way.

@robertnurnberg
Copy link
Contributor

It's not checked within the ci yet. But I can look into setting that up.

I think it would be a good idea. In my experience people do not keep metadata/documentation up to date unless it is enforced in some way.

That has now been implemented.

Some advantages:

(1) The Python logging framework is is thread safe so we do not
have to worry about printing from different threads.

(2) The Python logging framework is very configurable which
may be useful in the future.

This implementation is very rudimentary since I want to make sure
that other people also agree that this is a good thing to do.
@vdbergh
Copy link
Contributor Author

vdbergh commented Jun 7, 2025

I am going to close this. It is currently a bit of a distraction.

@vdbergh vdbergh closed this Jun 7, 2025
@vdbergh vdbergh reopened this Jun 7, 2025
@vdbergh vdbergh closed this Jun 7, 2025
sep="",
file=sys.stderr,
)
logger.error(f"Failed to update the atime of {path}: " + str(e))
Copy link
Collaborator

@ppigazzini ppigazzini Jun 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote few fishtest utils scripts using ruff check --select ALL to iron out all the warnings (eg https://github.com/official-stockfish/fishtest/blob/master/server/utils/delta_update_users.py). I learned than f-string in logging is a bad practice, because it is evaluated eagerly, even if that log level is disabled. This is CPU intensive if there are many DEBUG loggings, and it can create weird errors whit code enabled only in DEBUG mode.
logging provides %-formatting that defers string interpolation until after the level log check.

import logging

# A class that raises an error when its string representation is needed.
class Broken:
    def __str__(self):
        raise ValueError("Broken __str__ conversion!")

# Create an instance of the problematic class.
broken_instance = Broken()

# Configure the logger: set level to INFO so DEBUG messages are not output.
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Using an f-string: the expression inside {} is evaluated immediately,
# even though DEBUG messages are disabled.
try:
    logger.debug(f"F-string logging: {broken_instance}")
except Exception as e:
    print("F-string raised an exception:", e)

# Using %-formatting: the logger.debug method checks the log level first.
# Since DEBUG is disabled, the string interpolation never happens and
# broken_instance.__str__() is not called.
try:
    logger.debug("%%-formatting logging: %s", broken_instance)
    print("%%-formatting did NOT raise an exception.")
except Exception as e:
    print("%%-formatting raised an exception:", e)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that makes sense. I was wondering why the logging frame work has its own string interpolation.

Nowadays it would be natural to use t-strings (lazily evaluated f-strings).

Copy link
Collaborator

@ppigazzini ppigazzini Jun 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://peps.python.org/pep-0750/
template string will be shipped in python 3.14, so it could be used only server side (where not requiring pyramid explicit support).
PROD is running with python 3.13, but 3.13 is not officially tested by pyramid because it breaks on windows.
Pylons/pyramid#3767

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants