Skip to content

Don't rewrite it in Rust. Rewrite the 5% that's slow: profile your app, port the hot functions with your coding agent, prove they behave the same. Python, JS/TS, Ruby, Java, Kotlin, Go, PHP, C/C++, C#, R.

python: ignore a repeated SIGTERM while a worker writes its results

EL4CTEOe7df1d01956d
diff --git a/src/python/sitecustomize.py b/src/python/sitecustomize.py
index 0b9ec23..05022c8 100644
--- a/src/python/sitecustomize.py
+++ b/src/python/sitecustomize.py
@@ -24,7 +24,12 @@ def _fast_anything_watch_workers():
# instead, so the worker still leaves its results. Set first, before anything slow.
import signal
- signal.signal(signal.SIGTERM, lambda *_: sys.exit(0))
+ def _on_term(*_):
+ # a second SIGTERM must not cut the worker off while it writes its results
+ signal.signal(signal.SIGTERM, signal.SIG_IGN)
+ sys.exit(0)
+
+ signal.signal(signal.SIGTERM, _on_term)
state = None
try:
state = sys.modules.get("_fast_anything_state")