-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider auto-flushing *out* impl instead of System/out #31
Comments
In #32 I also note my confusion around |
The following, at least, didn't change behavior under CIDER for me, but maybe I have the wrong idea about implementation. ;; in (ns me.raynes.conch.low-level)
(defn auto-flush
"Returns a PrintWriter suitable for binding to *out* or *err*. This
writer will call .flush() on every write, ensuring that all output
is flushed, even if output was written from a background thread."
[writer]
(proxy [java.io.PrintWriter] [writer]
(write
([s]
(.write writer s)
(.flush writer))
([s ^Integer off ^Integer len]
(.write writer s off len)
(.flush writer)))))
(defn auto-stream-to-out
[process from & args]
(binding [*out* (auto-flush (java.io.StringWriter.))]
(apply stream-to process from *out* args))) user> (require '[me.raynes.conch.low-level :as sh])
nil
user> (def sh-python (sh/proc "python" "-i"))
#'user/sh-python
user> (future (sh/auto-stream-to-out sh-python :out))
#future[{:status :pending, :val nil} 0x2550e75a]
user> (future (sh/auto-stream-to-out sh-python :err))
#future[{:status :pending, :val nil} 0x51c018e5]
user> (sh/feed-from-string sh-python "1+3\n")
nil |
Sure, if it works it works. It does work, right? |
It didn't work for me. |
I think the point is to wrap whatever the thread-local value of out is, which is going to be a printwriter pointing to cider's streams, not an auto-flushing stringwriter. I can try to make a patch for this. |
Would this be an acceptable solution to the issue raised at
https://github.com/Raynes/conch/blob/master/src/me/raynes/conch/low_level.clj#L102
I think it's a better tradeoff than System/out, since output can show up in tooling repls such as cider.
The text was updated successfully, but these errors were encountered: