使用 leiningen 和 swank/slime 在 emacs 中运行 clojure 测试时停止无限循环
在某些类型的代码中,在不破坏堆栈的情况下相对容易导致无限循环。当使用 clojure-test 测试这种性质的代码时,有没有办法在不重新启动 swank 服务器的情况下中止当前正在运行的测试?
目前我的工作流程涉及
$ lein swank
使用 slime-connect
通过 emacs 连接到 swank,然后切换到测试,使用 Cc C-,
执行,测试运行直到无限循环,然后刚返回,但测试中一个 cpu 仍在不停地运转。我发现阻止这个问题的唯一方法是重新启动 lein swank,但这似乎是一个相对常见的问题?有人有更好的解决方案吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,在开发中编写无限循环是程序员的常见问题:)。答案很简单。它被称为“中断命令”,它是
Cc Cb
Leiningen 与此无关。这是 SLIME/Swank/Clojure。当您在 Emacs 中评估代码时,您将在 Clojure 中生成一个新线程。 SLIME 保留对这些线程的引用,并显示有多少线程在 Emacs 模型行中运行。如果您处于图形环境中,您可以单击模型行,其中指示您的名称空间并看到许多选项。一种选择是“中断命令”
Eval
(while true)
和Cc Cb
来获取一个显示java.lang.ThreadDeath
错误的对话框,其中可能包含只有一个选择。您可以键入0
或q
退出该线程,终止该错误消息缓冲区并将焦点返回到之前的缓冲区。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)
andC-c C-b
to get a dialog showing ajava.lang.ThreadDeath
error with probably just one option. You can type0
orq
to quit that thread, kill that error message buffer and return focus to your previous buffer.根据此旧讨论,添加
(use 'clojure.contrib.repl-utils))
和(add-break-thread!)
到 user.clj 应该使您能够按Cc Cc
用于将 SIGINT 传递给长时间运行的评估/进程。As per this old discussion, adding
(use 'clojure.contrib.repl-utils))
and(add-break-thread!)
to user.clj should enable you to pressC-c C-c
for passing SIGINT to the long running evaluation/processe.如果一切都失败了..
alt-x slime-quit-lisp
并重新启动 REPL。当然首先尝试 Psyllo 的答案。if all else fails..
alt-x slime-quit-lisp
and restart the REPL. try Psyllo's answer first of course.