在预建会话中,Clojure 警告会保持缓冲,除非客户端明确刷新,否则不会发送到客户端。
以下是一个使用 netcat
的预建会话示例(以 ;;
开始的行表示来自预建服务器的响应)
$ clojure -X clojure.core.server/start-server :name prepl :port 5555 :accept clojure.core.server/io-prepl :server-daemon false &
$ nc localhost 5555
(set! *warn-on-reflection* true)
;; {:tag :ret, :val "true", :ns "user", :ms 2, :form "(set! *warn-on-reflection* true)"}
(.toString (identity "foo"))
;; {:tag :ret, :val "\"foo\"", :ns "user", :ms 4, :form "(.toString (identity \"foo\"))"}
(binding [*out* *err*] (flush))
;; {:tag :err, :val "Reflection warning, NO_SOURCE_PATH:2:1 - reference to field toString can't be resolved.\n"}
;; {:tag :ret, :val "nil", :ns "user", :ms 4, :form "(binding [*out* *err*] (flush))"}
(defn identity [x] x)
;; {:tag :ret, :val "#'user/identity", :ns "user", :ms 3, :form "(defn identity [x] x)"}
(binding [*out* *err*] (flush))
;; {:tag :err, :val "WARNING: identity already refers to: #'clojure.core/identity in namespace: user, being replaced by: #'user/identity\n"}
;; {:tag :ret, :val "nil", :ns "user", :ms 2, :form "(binding [*out* *err*] (flush))"}
这似乎是由于预建的 *err*
PrintWriter 未启用 auto flushing
以及大多数 Clojure 警告未显式刷新所引起的。
这是否是一个需要解决的问题?或者这是预期行为,客户端应该负责定期刷新错误流?