Spaces:
Paused
Paused
Nicholas Bumgarner commited on
Commit ·
a53b1da
1
Parent(s): 488f97e
Fix stop_phoenix: minimize lock holding, close fds outside lock
Browse files
app.py
CHANGED
|
@@ -272,23 +272,40 @@ def start_phoenix_manual():
|
|
| 272 |
|
| 273 |
def stop_phoenix():
|
| 274 |
global _phoenix_proc, _ring_in_mm, _ring_out_mm, _ring_in_fd, _ring_out_fd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
with _state_lock:
|
| 276 |
-
if _ring_in_mm:
|
| 277 |
-
try:
|
| 278 |
-
ring_push(_ring_in_mm, SENTINEL_QUIT)
|
| 279 |
-
except Exception:
|
| 280 |
-
pass
|
| 281 |
if _phoenix_proc and _phoenix_proc.poll() is None:
|
| 282 |
_phoenix_proc.terminate()
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
return "Stopped"
|
| 293 |
|
| 294 |
|
|
|
|
| 272 |
|
| 273 |
def stop_phoenix():
|
| 274 |
global _phoenix_proc, _ring_in_mm, _ring_out_mm, _ring_in_fd, _ring_out_fd
|
| 275 |
+
# Send quit signal via ring buffer (no lock needed for ring_push)
|
| 276 |
+
if _ring_in_mm:
|
| 277 |
+
try:
|
| 278 |
+
ring_push(_ring_in_mm, SENTINEL_QUIT)
|
| 279 |
+
except Exception:
|
| 280 |
+
pass
|
| 281 |
with _state_lock:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
if _phoenix_proc and _phoenix_proc.poll() is None:
|
| 283 |
_phoenix_proc.terminate()
|
| 284 |
+
# Close ring buffers outside the lock to avoid blocking
|
| 285 |
+
if _ring_in_mm:
|
| 286 |
+
try:
|
| 287 |
+
_ring_in_mm.close()
|
| 288 |
+
except Exception:
|
| 289 |
+
pass
|
| 290 |
+
_ring_in_mm = None
|
| 291 |
+
if _ring_out_mm:
|
| 292 |
+
try:
|
| 293 |
+
_ring_out_mm.close()
|
| 294 |
+
except Exception:
|
| 295 |
+
pass
|
| 296 |
+
_ring_out_mm = None
|
| 297 |
+
if _ring_in_fd is not None:
|
| 298 |
+
try:
|
| 299 |
+
os.close(_ring_in_fd)
|
| 300 |
+
except Exception:
|
| 301 |
+
pass
|
| 302 |
+
_ring_in_fd = None
|
| 303 |
+
if _ring_out_fd is not None:
|
| 304 |
+
try:
|
| 305 |
+
os.close(_ring_out_fd)
|
| 306 |
+
except Exception:
|
| 307 |
+
pass
|
| 308 |
+
_ring_out_fd = None
|
| 309 |
return "Stopped"
|
| 310 |
|
| 311 |
|