简体   繁体   English

在使用leiningen和swank / slime的emacs中运行clojure测试时停止无限循环

[英]Stopping infinite loops while running clojure tests in emacs with leiningen and swank/slime

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? 使用clojure-test测试这种性质的代码时,有没有办法在不重启swank服务器的情况下中止当前运行的测试?

Currently my workflow has involved 目前我的工作流程涉及到

$ lein swank

Connect to swank with emacs using slime-connect , and switch to the the tests, execute with Cc C-, , tests run until infinite loop, then just return but one cpu is still churning away on the test. 使用slime-connect swank和emacs,切换到测试,用Cc C-,执行,测试运行直到无限循环,然后返回但是一个cpu仍然在测试中流失。 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? 我发现阻止这种情况的唯一方法是重新启动lein swank,但似乎这是一个相对常见的问题? Anyone have a better solution? 谁有更好的解决方案?

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 Cc Cb 它被称为“中断命令”,它是Cc Cb

Leiningen has nothing to do with this. 莱宁根与此毫无关系。 This is SLIME/Swank/Clojure. 这是SLIME / Swank / Clojure。 When you evaluate code in Emacs you are spawning a new thread within Clojure. 在Emacs中评估代码时,您将在Clojure中生成一个新线程。 SLIME keeps reference to those threads and shows you how many are running in the Emacs modeline. SLIME保留对这些线程的引用,并显示在Emacs模式行中运行的线程数。 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 Cc Cb to get a dialog showing a java.lang.ThreadDeath error with probably just one option. Eval (while true)Cc Cb获取一个对话框,显示java.lang.ThreadDeath错误,可能只有一个选项。 You can type 0 or q to quit that thread, kill that error message buffer and return focus to your previous buffer. 您可以键入0q退出该线程,终止该错误消息缓冲区并将焦点返回到先前的缓冲区。

根据这个旧的讨论 ,添加(use 'clojure.contrib.repl-utils))(add-break-thread!)到user.clj应该可以让你按Cc Cc将SIGINT传递给长时间运行的评估/处理。

if all else fails.. alt-x slime-quit-lisp and restart the REPL. 如果所有其他方法都失败了... alt-x slime-quit-lisp并重新启动REPL。 try Psyllo's answer first of course. 首先尝试Psyllo的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM