Spaces:
Sleeping
Sleeping
fix: run nginx as subprocess (not exec) to keep sync threads alive
Browse filesos.execvp replaces the Python process, killing all daemon threads
(sync, heartbeat, log streamer). Run nginx as Popen instead and
wait for it, keeping Python as PID 1 with threads running.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- entrypoint.py +10 -3
entrypoint.py
CHANGED
|
@@ -435,9 +435,17 @@ def main():
|
|
| 435 |
log(f" SSE: https://<space>.hf.space/runlog/stream")
|
| 436 |
log("========================================")
|
| 437 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
# Final save on SIGTERM
|
| 439 |
def on_sigterm(sig, frame):
|
| 440 |
log(f"signal {sig} — final save ...")
|
|
|
|
| 441 |
try:
|
| 442 |
save_and_upload()
|
| 443 |
except Exception as e:
|
|
@@ -447,9 +455,8 @@ def main():
|
|
| 447 |
signal.signal(signal.SIGTERM, on_sigterm)
|
| 448 |
signal.signal(signal.SIGINT, on_sigterm)
|
| 449 |
|
| 450 |
-
#
|
| 451 |
-
|
| 452 |
-
os.execvp("nginx", ["nginx", "-c", "/etc/nginx/nginx.conf", "-g", "daemon off;"])
|
| 453 |
|
| 454 |
|
| 455 |
if __name__ == "__main__":
|
|
|
|
| 435 |
log(f" SSE: https://<space>.hf.space/runlog/stream")
|
| 436 |
log("========================================")
|
| 437 |
|
| 438 |
+
# Start nginx as subprocess (NOT exec — we need threads to stay alive)
|
| 439 |
+
log("starting nginx on 0.0.0.0:7860 ...")
|
| 440 |
+
nginx_proc = subprocess.Popen(
|
| 441 |
+
["nginx", "-c", "/etc/nginx/nginx.conf", "-g", "daemon off;"]
|
| 442 |
+
)
|
| 443 |
+
log(f"[ OK ] nginx PID={nginx_proc.pid}")
|
| 444 |
+
|
| 445 |
# Final save on SIGTERM
|
| 446 |
def on_sigterm(sig, frame):
|
| 447 |
log(f"signal {sig} — final save ...")
|
| 448 |
+
nginx_proc.terminate()
|
| 449 |
try:
|
| 450 |
save_and_upload()
|
| 451 |
except Exception as e:
|
|
|
|
| 455 |
signal.signal(signal.SIGTERM, on_sigterm)
|
| 456 |
signal.signal(signal.SIGINT, on_sigterm)
|
| 457 |
|
| 458 |
+
# Wait for nginx to exit (keeps PID 1 = Python, threads alive)
|
| 459 |
+
nginx_proc.wait()
|
|
|
|
| 460 |
|
| 461 |
|
| 462 |
if __name__ == "__main__":
|