Note that there are some explanatory texts on larger screens.

plurals
  1. POClojure core.async, CPU hangs after timeout. Anyway to properly kill macro thread produced by (go..) block?
    text
    copied!<p>Based on <a href="https://github.com/clojure/core.async/blob/e4acc9c30c283ac677e72010bde01971f61293ac/examples/walkthrough.clj#L97-L108" rel="noreferrer">core.async walk through example</a>, I created below similar code to handle some CPU intensive jobs using multiple channels with a timeout of 10 seconds. However after the main thread returns, the CPU usage remains around 700% (8 CPUs machine). I have to manually run nrepl-close in emacs to shut down the Java process.</p> <p>Is there any proper way to kill macro thread produced by (go..) block ? I tried close! each chan, but it doesn't work. I want to make sure CPU usage back to 0 by Java process after main thread returns.</p> <pre><code>(defn [] RETURNED-STR-FROM-SOME-CPU-INTENSE-JOB (do... (str ...))) (let [n 1000 cs (repeatedly n chan)] (doseq [c cs] (go (&gt;! c (RETURNED-STR-FROM-SOME-CPU-INTENSE-JOB )))) (dotimes [i n] (let [[result source] (alts!! (conj cs (timeout 10000))) ] ;;wait for 10 seconds for each job (if (list-contains? cs source) ;;if returned chan belongs to cs (prn "OK JOB FINISHED " result) (prn "JOB TIMEOUT") ))) (doseq [i cs] (close! i)) ;;not useful for "killing" macro thread (prn "JOBS ARE DONE")) ;;Btw list-contains? function is used to judge whether an element is in a list ;;http://stackoverflow.com/questions/3249334/test-whether-a-list-contains-a-specific-value-in-clojure (defn list-contains? [coll value] (let [s (seq coll)] (if s (if (= (first s) value) true (recur (rest s) value)) false))) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload