babashka / babashka.nrepl

The nREPL server from babashka as a library, so it can be used from other SCI-based CLIs.
Eclipse Public License 1.0
52 stars 15 forks source link

implement interrupt #23

Closed retrogradeorbit closed 2 years ago

retrogradeorbit commented 4 years ago

I'm beginning to need interrupt support. This one will be interesting...

https://github.com/clojure-emacs/cider/blob/dffe8c5c0bb6d07157e3db7322a0c8076ccb3a7b/cider-client.el#L387

borkdude commented 4 years ago

I’ve already tried implementing this. The JVM uses Thread/stop for this, which has long been deprecated and not supported because of this on GraalVM.

On Tue, 7 Jul 2020 at 05:31, Crispin Wellington notifications@github.com wrote:

I'm beginning to need interrupt support. This one will be interesting...

https://github.com/clojure-emacs/cider/blob/dffe8c5c0bb6d07157e3db7322a0c8076ccb3a7b/cider-client.el#L387

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/babashka/babashka.nrepl/issues/23, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACFSBVVBPHMMI5H43IL2EDR2KJHPANCNFSM4OSMEIUQ .

-- https://www.michielborkent.nl https://www.eetvoorjeleven.nu

retrogradeorbit commented 4 years ago

maybe we could wrap the execution of the repl expression in a future, and use future-cancel? https://github.com/clojure/clojure/blob/clojure-1.10.1/src/clj/clojure/core.clj#L7000

this might not always work. Cancels the future "if possible". I will give it a test see how it behaves.

retrogradeorbit commented 4 years ago
# time bb -e '(let [f (future (Thread/sleep 10000))] (Thread/sleep 1000) (future-cancel f) @f)'
java.util.concurrent.CancellationException: [at line 1, column 78]

real    0m1.023s
user    0m0.005s
sys 0m0.014s
borkdude commented 4 years ago

See https://stackoverflow.com/questions/11520394/why-do-cancelled-clojure-futures-continue-using-cpu for problems around this approach.

On Thu, 16 Jul 2020 at 08:45, Crispin Wellington notifications@github.com wrote:

time bb -e '(let [f (future (Thread/sleep 10000))] (Thread/sleep 1000) (future-cancel f) @f)'

java.util.concurrent.CancellationException: [at line 1, column 78]

real 0m1.023s user 0m0.005s sys 0m0.014s

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/babashka/babashka.nrepl/issues/23#issuecomment-659194169, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACFSBUJMET7VU5ZM5WXDMDR32OXLANCNFSM4OSMEIUQ .

-- https://www.michielborkent.nl https://www.eetvoorjeleven.nu

borkdude commented 2 years ago

Closing this as I don't know how to solve this reliably. Might revisit this when bb is based on JDK19 with Virtual Threads.