Fork me on GitHub

How do I deal with agents without breaking Cider's connection? Running (shutdown-agents) results in this error in the terminal, and I have to restart the REPL entirely:

Exception updating the ns-cache #error {
 :cause Task [email protected] rejected from [email protected][Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 90]
 [{:type java.util.concurrent.RejectedExecutionException
   :message Task [email protected] rejected from [email protected][Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 90]
   :at [java.util.concurrent.ThreadPoolExecutor$AbortPolicy rejectedExecution 2055]}]
 [[java.util.concurrent.ThreadPoolExecutor$AbortPolicy rejectedExecution 2055]
  [java.util.concurrent.ThreadPoolExecutor reject 825]
  [java.util.concurrent.ThreadPoolExecutor execute 1355]
  [clojure.lang.Agent$Action execute 90]
  [clojure.lang.Agent enqueue 268]
  [clojure.lang.Agent dispatchAction 255]
  [clojure.lang.Agent dispatch 241]
  [clojure.core$send_via invokeStatic core.clj 2113]
  [clojure.core$send_via doInvoke core.clj 2105]
  [clojure.lang.RestFn applyTo 146]
  [clojure.core$apply invokeStatic core.clj 673]
  [clojure.core$send invokeStatic core.clj 2124]
  [clojure.core$send doInvoke core.clj 2115]
  [clojure.lang.RestFn invoke 490]
  [cider.nrepl.middleware.track_state$make_transport$reify__5814 send track_state.clj 230]
  [nrepl.middleware.interruptible_eval$interruptible_eval$fn__994$fn__1000 invoke interruptible_eval.clj 153]
  [clojure.lang.AFn run 22]
  [nrepl.middleware.session$session_exec$main_loop__1062 invoke session.clj 206]
  [clojure.lang.AFn run 22]
  [java.lang.Thread run 830]]}


i don't think that's something you should call unless you are ready for the process to end. you are stopping two global executors and CIDER uses those global threadpools


Hmm, I'm just learning about Agents and core.async, and tutorials mention the use of shutdown-agents to kill off running threads. I can't seem find any more fine-grained methods for doing so without affecting the entire global threadpool


that's generally to kill threads in preparation of shutting down


eg. if I run a (go (while true (>! ch :msg))) there's now a process running indefinitely in the background, how do I stop it?


if you need more cooperative "stop doing work" there are other means. closing channels


there's lots of ways but that's not a great thing to do if you ever want to stop it


a common thing to do is make that into a loop that can recur when the puts are successful, etc


Right, this is just in the context of messing around with experiments in the REPL


Just wanted to make sure if this was expected behavior for Cider


yeah that would be expected. you stopped the agent executors, and then got an error that CIDER couldn't send a message to an agent

👌 3