Skip to content

Commit 996021e

Browse files
committed
Fixes #216
1 parent cf47c2b commit 996021e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/libpython_clj2/python/io_redirect.clj

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
[clojure.tools.logging :as log])
1111
(:import [java.io Writer]))
1212

13+
(set! *warn-on-reflection* true)
14+
1315

1416
(defn self->writer
1517
^Writer [self]
@@ -32,7 +34,9 @@
3234
(py-ffi/py-none))
3335
{:arg-converter identity})
3436
"flush" (py-class/make-tuple-instance-fn
35-
(constantly (py-ffi/py-none)))
37+
(fn [self & args] (.flush (self->writer self)) (py-ffi/py-none))
38+
{:arg-converter identity} ;;avoid paying anything for argument conversion
39+
)
3640
"isatty" (py-class/make-tuple-instance-fn
3741
(constantly (py-ffi/py-false)))})))
3842

@@ -53,3 +57,16 @@
5357
[]
5458
(setup-std-writer #'*err* "stderr")
5559
(setup-std-writer #'*out* "stdout"))
60+
61+
62+
(comment
63+
;;Ensure flush works
64+
(require '[libpython-clj2.python :as py])
65+
(py/initialize!)
66+
(def _)
67+
(def _ (py/run-simple-string "import sys\nimport time"))
68+
(py/run-simple-string "for i in range(10):
69+
\ttime.sleep(1)
70+
\tsys.stderr.write('#')
71+
\tsys.stdout.flush()")
72+
)

0 commit comments

Comments
 (0)