babashka/process updates
This commit is contained in:
parent
fcd30063f7
commit
1c10221f86
3 changed files with 18 additions and 15 deletions
2
process
2
process
|
|
@ -1 +1 @@
|
|||
Subproject commit c3d861b574dd22a2136ff6fc2407f48b480d3a7a
|
||||
Subproject commit 90540747422efd0ea7a0128bd2827545de1333e0
|
||||
|
|
@ -5,20 +5,25 @@
|
|||
|
||||
(def tns (sci/create-ns 'babashka.process nil))
|
||||
|
||||
(def escape-fn (sci/copy-var process/*escape-fn* tns))
|
||||
(def escape-fn (sci/copy-var process/*default-escape-fn* tns))
|
||||
(def shutdown-hook (sci/copy-var process/*default-shutdown-hook* tns))
|
||||
|
||||
(defn process [& args]
|
||||
(binding [process/*escape-fn* @escape-fn]
|
||||
(binding [process/*default-escape-fn* @escape-fn
|
||||
process/*default-shutdown-hook* @shutdown-hook]
|
||||
(apply process/process args)))
|
||||
|
||||
(defn pb [& args]
|
||||
(binding [process/*escape-fn* @escape-fn]
|
||||
(binding [process/*escape-fn* @escape-fn
|
||||
process/*default-shutdown-hook* @shutdown-hook]
|
||||
(apply process/pb args)))
|
||||
|
||||
(def process-namespace
|
||||
{'process (copy-var process tns)
|
||||
'check (copy-var process/check tns)
|
||||
'pb (copy-var pb tns)
|
||||
'start (copy-var process/start tns)
|
||||
'pipeline (copy-var process/pipeline tns)
|
||||
'$ (copy-var process/$ tns)
|
||||
'*escape-fn* escape-fn})
|
||||
'*default-escape-fn* escape-fn
|
||||
'*default-shutdown-hook* shutdown-hook})
|
||||
|
|
|
|||
|
|
@ -1,17 +1,14 @@
|
|||
(ns killing-me-softly
|
||||
(:refer-clojure :exclude [descendants]))
|
||||
|
||||
(import 'java.util.List)
|
||||
|
||||
(set! *warn-on-reflection* true)
|
||||
|
||||
(defn child-process-handles [^java.lang.ProcessHandle x]
|
||||
(distinct
|
||||
(cons x
|
||||
(mapcat child-process-handles
|
||||
(iterator-seq (.iterator (.descendants x)))))))
|
||||
|
||||
(defn start-spawning [& args]
|
||||
(let [depth (or (System/getenv "DEPTH") "0")
|
||||
depth (Integer/parseInt depth)]
|
||||
(when-not (= 4 depth)
|
||||
(when-not (= 4 depth) ;; process at depth 4 dies immediately
|
||||
(let [pb (doto (ProcessBuilder. ^List args)
|
||||
(.inheritIO))
|
||||
_ (.put (.environment pb) "DEPTH"
|
||||
|
|
@ -21,9 +18,10 @@
|
|||
(do
|
||||
(Thread/sleep 500)
|
||||
(run! (fn [^java.lang.ProcessHandle handle]
|
||||
(do (prn (.pid handle))
|
||||
(.destroy handle)))
|
||||
(child-process-handles (.toHandle proc))))
|
||||
(prn (.pid handle))
|
||||
(.destroy handle))
|
||||
(let [handle (.toHandle proc)]
|
||||
(cons handle (iterator-seq (.iterator (.descendants handle)))))))
|
||||
(Thread/sleep 100000000))))))
|
||||
|
||||
(start-spawning "./bb" *file*)
|
||||
|
|
|
|||
Loading…
Reference in a new issue