Skip to content

Commit

Permalink
Fix deadlock during make on Windows
Browse files Browse the repository at this point in the history
In the MSYS2 Python environment, an issue has been observed where
STDERR output is delayed until all STDOUT output is complete when
running an application with subprocess.
This causes a deadlock in the STDOUT print when a `make` process
writes a warning message to STDERR.

Raise worker version to 226 (also server side)
  • Loading branch information
vdbergh authored and ppigazzini committed Feb 23, 2024
1 parent 121549e commit e9a6f05
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion server/fishtest/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
on how frequently the main instance flushes its run cache.
"""

WORKER_VERSION = 225
WORKER_VERSION = 226

"""
begin api_schema
Expand Down
12 changes: 4 additions & 8 deletions worker/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,44 +693,40 @@ def setup_engine(
# skip temporary the profiled build for apple silicon, see
# https://stackoverflow.com/questions/71580631/how-can-i-get-code-coverage-with-clang-13-0-1-on-mac
make_cmd = "build" if arch == "apple-silicon" else "profile-build"
cmd = "make -j {} {} ARCH={} COMP={}".format(concurrency, make_cmd, arch, comp)
cmd = f"make -j {concurrency} {make_cmd} ARCH={arch} COMP={comp}".split()

# append -DNNUE_EMBEDDING_OFF to existing CXXFLAGS environment variable, if any
cxx = os.environ.get("CXXFLAGS", "") + " -DNNUE_EMBEDDING_OFF"
env = dict(os.environ, CXXFLAGS=cxx.strip())

with subprocess.Popen(
cmd,
shell=True,
env=env,
start_new_session=False if IS_WINDOWS else True,
stdout=subprocess.PIPE,
stdout=None,
stderr=subprocess.PIPE,
universal_newlines=True,
bufsize=1,
close_fds=not IS_WINDOWS,
) as p:
try:
for out in p.stdout:
print(out.strip())
errors = p.stderr.readlines()
except Exception as e:
if not IS_WINDOWS:
os.killpg(p.pid, signal.SIGINT)
raise WorkerException(
f"Executing {cmd} raised Exception: {e.__class__.__name__}: {str(e)}",
e=e,
)
errors = p.stderr.readlines()
if p.returncode:
raise WorkerException("Executing {} failed. Error: {}".format(cmd, errors))

# TODO: 'make strip' works fine with the new Makefile,
# 'try' should be safely dropped in the future
try:
subprocess.run(
"make strip COMP={}".format(comp),
["make", "strip", f"COMP={comp}"],
stderr=subprocess.DEVNULL,
shell=True,
check=True,
)
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion worker/sri.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"__version": 225, "updater.py": "Mg+pWOgGA0gSo2TuXuuLCWLzwGwH91rsW1W3ixg3jYauHQpRMtNdGnCfuD1GqOhV", "worker.py": "Hyq1aYXjX1uofUnSW9EGBXTQN0Jfjz7+LExmFxe6qLQEX1w8vxFQOpWTrRV4YZZz", "games.py": "VtjJDf5aPFs93Ni/uB1JBr4GpSxjFWgO/qd6KV2Rra620ckS7YjhXq7r/RnS8SPT"}
{"__version": 226, "updater.py": "Mg+pWOgGA0gSo2TuXuuLCWLzwGwH91rsW1W3ixg3jYauHQpRMtNdGnCfuD1GqOhV", "worker.py": "AlzBfLw8QpQx5mQmOXedSHxcBG5v+Jw5pyW3gTeUsdDzi+23Jhf7T8gcIUGQFu0A", "games.py": "x0RFYFYsRObu/828o5qz0BBA9sAhiyiLSDJQvxFXpuqTEgZWZfN+jo5JFVUiemHX"}
2 changes: 1 addition & 1 deletion worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Several packages are called "expression".
# So we make sure to use the locally installed one.

WORKER_VERSION = 225
WORKER_VERSION = 226
FILE_LIST = ["updater.py", "worker.py", "games.py"]
HTTP_TIMEOUT = 30.0
INITIAL_RETRY_TIME = 15.0
Expand Down

0 comments on commit e9a6f05

Please sign in to comment.