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.
Rust agent-skillsai-agentsclaude-codeclaude-code-plugincodexdeveloper-toolsffimcpmcp-servernapi-rsnodejsoptimizationperformanceprofilerpyo3pythonrewrite-it-in-rustrubyrusttypescript
python: write a terminated worker's results from its SIGTERM handler
Mohit Mishra0ecbcbc56a0b
diff --git a/src/python/sitecustomize.py b/src/python/sitecustomize.pyindex 05022c8..92c096c 100644--- a/src/python/sitecustomize.py+++ b/src/python/sitecustomize.py@@ -19,18 +19,24 @@ def _fast_anything_watch_workers():returndef _bootstrap(self, *args, **kwargs):+ state = Noneif os.name == "posix":- # Pool.terminate() (and with Pool(...) as p) ends workers with SIGTERM: exit normally- # instead, so the worker still leaves its results. Set first, before anything slow.+ # Pool.terminate() (and with Pool(...) as p) ends workers with SIGTERM: write the+ # worker's results first, then end it the way SIGTERM would have. Not by raising+ # SystemExit: that can land in the finally below before the results are written, or+ # be swallowed (a handler can run inside a __del__), leaving a worker that never exits.+ # Set first, before anything slow.import signaldef _on_term(*_):# a second SIGTERM must not cut the worker off while it writes its resultssignal.signal(signal.SIGTERM, signal.SIG_IGN)- sys.exit(0)+ if state is not None:+ state.finish()+ signal.signal(signal.SIGTERM, signal.SIG_DFL)+ os.kill(os.getpid(), signal.SIGTERM)signal.signal(signal.SIGTERM, _on_term)- state = Nonetry:state = sys.modules.get("_fast_anything_state")if state is None: # a fresh interpreter (spawn, forkserver): load the runner