This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-05
Channels
- # aleph (2)
- # announcements (3)
- # architecture (5)
- # beginners (51)
- # biff (5)
- # cider (1)
- # clerk (8)
- # clj-kondo (6)
- # cljsrn (5)
- # clojure (31)
- # clojure-europe (42)
- # clojure-nl (1)
- # clojure-norway (21)
- # clojure-uk (3)
- # emacs (11)
- # fulcro (2)
- # graphql (6)
- # hugsql (1)
- # jobs (2)
- # leiningen (3)
- # lsp (3)
- # malli (13)
- # missionary (1)
- # off-topic (7)
- # pathom (7)
- # polylith (27)
- # reagent (14)
- # reitit (3)
- # remote-jobs (7)
- # shadow-cljs (20)
- # spacemacs (4)
- # sql (3)
- # tools-build (4)
- # xtdb (7)
when i launch a lot of clojure processes via pmap, i feel like i should be able to cancel all the jobs via cider interrupt evaluation. But instead, emacs seems to hang, (it's responding periodically) and my computer fans are working overtime.
cider’s interrupt is a deprecated and not great way to stop a thread. But I think you are forgetting what you have done: cancelling a thread is one thing. But you have launched a bunch of other tasks on other threads and hope that your cancellation is transitively passed along to the other threads you’ve started. I don’t think that’s in the realm of what is offered by the thread cancellation
Cider-interrupt is deprecated? the docs don't indicate as much. huh. I guess communicating state between parallel processes sounds like a job for core async or something like that then right?
(defn- interrupt-stop
"This works as follows
1. Calls interrupt
2. Wait 100ms. This is mainly to allow thread that respond quickly to
interrupts to send a message back in response to the interrupt. Significantly,
this includes an exception thrown by `Thread/sleep`.
3. Asynchronously: wait another 5000ms for the thread to cleanly terminate.
Only calls `.stop` if it fails to do so (and risk state corruption)
This set of behaviours strikes a balance between allowing a thread to respond
to an interrupt, but also ensuring we actually kill runaway processes.
If required, a future feature could make both timeouts configurable, either
as a server config or parameters provided by the `interrupt` message."
[^Thread t]
(.interrupt t)
(Thread/sleep 100)
(noisy-future
(Thread/sleep 5000)
(when-not (= (Thread$State/TERMINATED)
(.getState t))
(.stop t))))
So it calls interrupt
and then 5 seconds later calls stop
. And stop:
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Thread.html#stop()Pmap mixes laziness and concurrency so hard to say, but generally when you interrupt it you are just interrupting the waiting for it to complete, the threads doing the work keep going
@U0NCTKEV8, that makes sense. Thanks.
thanks for sharing that code dpsutton 👍