Stopping infinite loops while running clojure tests in emacs with leiningen and swank/slime
Asked Answered
W

3

12

In certain kinds of code it's relatively easy to cause an infinite loop without blowing the stack. When testing code of this nature using clojure-test, is there a way to abort the current running tests without restarting the swank server?

Currently my workflow has involved

$ lein swank

Connect to swank with emacs using slime-connect, and switch to the the tests, execute with C-c C-,, tests run until infinite loop, then just return but one cpu is still churning away on the test. The only way to stop this I have found is to restart lein swank, but it seems like this would be a relatively common problem? Anyone have a better solution?

Weingartner answered 25/2, 2011 at 3:50 Comment(0)
S
13

Yes, it is a common problem for programmers to write infinite loops in development :). And the answer is very simple. It's called "Interrupt Command" and it is C-c C-b

Leiningen has nothing to do with this. This is SLIME/Swank/Clojure. When you evaluate code in Emacs you are spawning a new thread within Clojure. SLIME keeps reference to those threads and shows you how many are running in the Emacs modeline. If you're in a graphical environment you can click the modeline where it indicates your namespace and see lots of options. One option is "Interrupt Command"

Eval (while true) and C-c C-b to get a dialog showing a java.lang.ThreadDeath error with probably just one option. You can type 0 or q to quit that thread, kill that error message buffer and return focus to your previous buffer.

Smallclothes answered 25/2, 2011 at 15:58 Comment(1)
It is bound to cider-interrupt in CIDER and it works like a charm.Pomfrey
A
2

As per this old discussion, adding (use 'clojure.contrib.repl-utils)) and (add-break-thread!) to user.clj should enable you to press C-c C-c for passing SIGINT to the long running evaluation/processe.

Adopted answered 25/2, 2011 at 11:34 Comment(1)
My current Emacs setup binds C-c C-c to slime-interrupt which behaves as you would expectMulhouse
I
1

if all else fails.. alt-x slime-quit-lisp and restart the REPL. try Psyllo's answer first of course.

Idolater answered 25/2, 2011 at 19:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.