Amogh1221 commited on
Commit
bba4fd9
·
verified ·
1 Parent(s): 9cc6f03

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +19 -5
main.py CHANGED
@@ -134,24 +134,38 @@ async def get_engine():
134
  _GLOBAL_ENGINE = None
135
 
136
  if not os.path.exists(ENGINE_PATH):
137
- raise HTTPException(status_code=500, detail=f"Engine NOT FOUND at {ENGINE_PATH}")
138
 
 
139
  try:
140
  transport, engine = await chess.engine.popen_uci(ENGINE_PATH)
 
141
 
142
  # Configure once
143
- await engine.configure({"Hash": 256, "Threads": 1}) # More conservative for singleton
144
 
145
  if os.path.exists(NNUE_PATH):
 
146
  try:
147
  await engine.configure({"EvalFile": NNUE_PATH})
148
- except Exception:
149
- pass
 
 
 
150
 
151
  _GLOBAL_ENGINE = engine
152
  return engine
153
  except Exception as e:
154
- raise HTTPException(status_code=500, detail=f"Failed to start engine: {str(e)}")
 
 
 
 
 
 
 
 
155
 
156
  def get_normalized_score(info) -> tuple[float, Optional[int]]:
157
  """Returns the score from White's perspective in centipawns."""
 
134
  _GLOBAL_ENGINE = None
135
 
136
  if not os.path.exists(ENGINE_PATH):
137
+ raise HTTPException(status_code=500, detail=f"Engine binary NOT FOUND at {ENGINE_PATH}")
138
 
139
+ print(f"[DEBUG] Attempting to start engine at {ENGINE_PATH}")
140
  try:
141
  transport, engine = await chess.engine.popen_uci(ENGINE_PATH)
142
+ print(f"[DEBUG] Engine process started. ID: {transport.get_pid()}")
143
 
144
  # Configure once
145
+ await engine.configure({"Hash": 128, "Threads": 1})
146
 
147
  if os.path.exists(NNUE_PATH):
148
+ print(f"[DEBUG] Found NNUE at {NNUE_PATH}. Attempting to load...")
149
  try:
150
  await engine.configure({"EvalFile": NNUE_PATH})
151
+ print("[DEBUG] NNUE loaded successfully.")
152
+ except Exception as ne:
153
+ print(f"[ERROR] NNUE load failed: {str(ne)}")
154
+ else:
155
+ print(f"[WARNING] NNUE NOT FOUND at {NNUE_PATH}")
156
 
157
  _GLOBAL_ENGINE = engine
158
  return engine
159
  except Exception as e:
160
+ print(f"[CRITICAL] Engine failed to start: {str(e)}")
161
+ # Try to gather more info by running the binary directly briefly
162
+ import subprocess
163
+ try:
164
+ diag = subprocess.run([ENGINE_PATH, "uci"], capture_output=True, text=True, timeout=2)
165
+ print(f"[DIAG] Engine output: {diag.stdout} | Error: {diag.stderr}")
166
+ except Exception as de:
167
+ print(f"[DIAG] Could not run diagnosis: {str(de)}")
168
+ raise HTTPException(status_code=500, detail=f"Engine Crash: {str(e)}")
169
 
170
  def get_normalized_score(info) -> tuple[float, Optional[int]]:
171
  """Returns the score from White's perspective in centipawns."""