当在Eclipse / CounterClockWise中使用线程时,输出发送到控制台而不是REPL [英] Output is sent to console instead of REPL when using threads in Eclipse/CounterClockWise

查看:206
本文介绍了当在Eclipse / CounterClockWise中使用线程时,输出发送到控制台而不是REPL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从指南尝试了此代码:

I tried this code from this guide:

(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中,另一部分显示在控制台因为我通常有它隐藏,因为我不使用它)。

When I execute it, part of the output shows up in the REPL, and the other part shows up in the console (which pops up since I usually have it hidden because I don't use it).

我想把所有的输出到REPL窗口,我怎么实现呢? p>

I want to send all the output to the REPL window, how can I achieve that?

推荐答案

这是因为 * out * 。您可以手动绑定:

It's because *out* is not bound to REPL writer in new thread. You can bind it manually:

(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 / CounterClockWise中使用线程时,输出发送到控制台而不是REPL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆