-
-
Notifications
You must be signed in to change notification settings - Fork 29
-
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shutdown hook #25
Comments
Also see #19. |
At work I have a script which didn't kill all subprocesses. I needed to do this: (ns dev
(:require [babashka.process :refer [process]]))
(defn child-process-handles [^java.lang.ProcessHandle x]
(distinct
(cons x
(mapcat child-process-handles
(iterator-seq (.iterator (.descendants x)))))))
(defn kill [proc]
(run! (fn [^java.lang.ProcessHandle handle]
(prn (.pid handle))
(.destroy handle))
(child-process-handles (.toHandle (:proc proc)))))
(defn cljs []
(let [p (process ["./clojure" "-A:frontend:cljs/dev"] {:out :inherit
:err :inherit})]
(-> (Runtime/getRuntime)
(.addShutdownHook (Thread. #(kill p)))))) |
borkdude
added a commit
that referenced
this issue
Oct 20, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add option
:shutdown-hook
which defaults to(fn [proc] (.destroy (:proc proc)))
and can be overridden with any arity-1 function.The text was updated successfully, but these errors were encountered: