Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,14 +24,12 @@ async def run_benchmark(orders: int = 1000000, cancel: float = 0.20, market: flo
|
|
| 24 |
"--quiet"
|
| 25 |
]
|
| 26 |
|
| 27 |
-
# BUG FIX: Original code had `result` referenced in the JSONDecodeError
|
| 28 |
-
# handler, but `result` is only assigned inside the try block when
|
| 29 |
-
# check=True raises CalledProcessError before the assignment can happen.
|
| 30 |
-
# This would throw a NameError, masking the real error. Fix: capture
|
| 31 |
-
# stdout explicitly before calling check, so result is always defined.
|
| 32 |
stdout_data = ""
|
| 33 |
try:
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 35 |
stdout_data = proc.stdout
|
| 36 |
|
| 37 |
if proc.returncode != 0:
|
|
@@ -41,7 +39,13 @@ async def run_benchmark(orders: int = 1000000, cancel: float = 0.20, market: flo
|
|
| 41 |
|
| 42 |
return json.loads(stdout_data)
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
except json.JSONDecodeError:
|
| 45 |
return {"error": f"Invalid JSON output from C++: {stdout_data!r}"}
|
|
|
|
| 46 |
except Exception as e:
|
| 47 |
return {"error": f"Server execution error: {str(e)}"}
|
|
|
|
| 24 |
"--quiet"
|
| 25 |
]
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
stdout_data = ""
|
| 28 |
try:
|
| 29 |
+
# BUG FIX #6: Added timeout=120 — 20M benchmark takes ~35s on cloud VM.
|
| 30 |
+
# Without timeout, HF Space HTTP request silently kills the process at
|
| 31 |
+
# ~30s leaving the frontend hanging with no error message.
|
| 32 |
+
proc = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
|
| 33 |
stdout_data = proc.stdout
|
| 34 |
|
| 35 |
if proc.returncode != 0:
|
|
|
|
| 39 |
|
| 40 |
return json.loads(stdout_data)
|
| 41 |
|
| 42 |
+
except subprocess.TimeoutExpired:
|
| 43 |
+
# BUG FIX #6: Catch timeout explicitly and return clean error JSON
|
| 44 |
+
# instead of crashing the FastAPI worker process.
|
| 45 |
+
return {"error": "Benchmark timed out after 120 seconds. Try fewer orders (1M or 5M)."}
|
| 46 |
+
|
| 47 |
except json.JSONDecodeError:
|
| 48 |
return {"error": f"Invalid JSON output from C++: {stdout_data!r}"}
|
| 49 |
+
|
| 50 |
except Exception as e:
|
| 51 |
return {"error": f"Server execution error: {str(e)}"}
|