eclipse - 在 Eclipse/CounterClockWise 中使用线程时,输出被发送到控制台而不是 REPL

标签 eclipse clojure counterclockwise

我从 this 尝试了这段代码指导:

(defn my-fn [ms]
  (println "entered my-fn")
  (Thread/sleep ms)
  (println "leaving my-fn"))

(let [thread (Thread. #(my-fn 1))]
  (.start thread)
  (println "started thread")
  (while (.isAlive thread)
    (print ".")
    (flush))
  (println "thread stopped"))

当我执行它时,部分输出显示在 REPL 中,另一部分显示在控制台中(因为我通常隐藏它,因为我不使用它,所以它会弹出)。

我想将所有输出发送到 REPL 窗口,我该如何实现?

最佳答案

这是因为*out*未绑定(bind)到新线程中的 REPL 编写器。您可以手动绑定(bind)它:

(let [thread (let [out *out*] 
               (Thread. #(binding [*out* out] 
                           (my-fn 1))))]
  (.start thread)
  (println "started thread")
  (while (.isAlive thread)
    (print ".")
    (flush))
  (println "thread stopped"))

关于eclipse - 在 Eclipse/CounterClockWise 中使用线程时,输出被发送到控制台而不是 REPL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15197914/

相关文章:

java - 领英 API。如何获得一个弹出窗口,要求用户单击“允许”并自动获取代码,而不是在 Linkedin 中复制和粘贴

eclipse - 如何在逆时针/Eclipse中的Leiningen项目中顺利运行测试?

algorithm - 逆时针排列凹多边形顶点

eclipse - 在逆时针严格paredit模式下删除多余的括号

clojure - 为什么我的 lein re-frame 模板中有 clj 和 cljs 文件夹?

java - 在 Clojure 中 : Error executing a Java call with let inside a function but not in REPL

java - 选择 Eclipse 上 Ubuntu 中的 JTextField 上看不到的文件路径

eclipse - 调试 - GNU ARM 裸机开发

java - 什么包包含 org/eclipse/ocl/helper/OCLSyntaxHelper?

java - 俄罗斯方 block 的 vector 或 Java 数组?