Spaces:
Sleeping
Sleeping
deploy from github
Browse files- core/simulation.py +13 -10
core/simulation.py
CHANGED
|
@@ -88,16 +88,19 @@ class Simulation:
|
|
| 88 |
print(f"Boredom Penalty: Agents lose tokens after 2+ consecutive do_nothing actions")
|
| 89 |
print()
|
| 90 |
|
| 91 |
-
# Register graceful shutdown handler
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
def _save_progress(sim):
|
| 103 |
"""Save current progress as incomplete run."""
|
|
|
|
| 88 |
print(f"Boredom Penalty: Agents lose tokens after 2+ consecutive do_nothing actions")
|
| 89 |
print()
|
| 90 |
|
| 91 |
+
# Register graceful shutdown handler (may not work in all environments)
|
| 92 |
+
try:
|
| 93 |
+
import signal
|
| 94 |
+
def shutdown_handler(signum, frame):
|
| 95 |
+
print(f"\n[SHUTDOWN] Received signal, saving progress...")
|
| 96 |
+
_save_progress(self)
|
| 97 |
+
print(f"[SHUTDOWN] Run marked as incomplete")
|
| 98 |
+
raise SystemExit(0)
|
| 99 |
+
|
| 100 |
+
signal.signal(signal.SIGTERM, shutdown_handler)
|
| 101 |
+
signal.signal(signal.SIGINT, shutdown_handler)
|
| 102 |
+
except (ValueError, AttributeError) as e:
|
| 103 |
+
print(f"[WARN] Signal handlers not available: {e}")
|
| 104 |
|
| 105 |
def _save_progress(sim):
|
| 106 |
"""Save current progress as incomplete run."""
|