On Monday, 25 March 2019 14:31:18 CET Richard W.M. Jones wrote:
On Fri, Mar 22, 2019 at 04:33:41PM +0100, Pino Toscano wrote:
> Enhance the helper printf function for machine readable output to always
> flush after each string: this way, readers of the machine readable
> stream can get the output as soon as it is outputted.
> ---
> common/mltools/tools_utils.ml | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/common/mltools/tools_utils.ml b/common/mltools/tools_utils.ml
> index 5a35708cd..ade4cb37f 100644
> --- a/common/mltools/tools_utils.ml
> +++ b/common/mltools/tools_utils.ml
> @@ -59,7 +59,11 @@ let machine_readable () =
> | None -> None
> | Some chan ->
> let pr fs =
> - ksprintf (output_string chan) fs
> + let out s =
> + output_string chan s;
> + flush chan
> + in
> + ksprintf out fs
> in
> Some { pr }
I was looking to see if any of the existing calls to machine_readable
are using %! (a format directive which causes the channel to be
flushed). I had expected there would be some, but my simple "git
grep"s aren't turning up anything right now.
Yes, I know about %!, and that was my first attempt in patch 4, which
had:
pr "%s\n%!" (JSON.string_of_doc ~fmt:JSON.Compact json)
However, it did not seem to work: the output seemed batched every 1/2
minutes or so, and even extra `pr "%!"` did not change anything.
Even when using Obj.magic, the fd still is not flushed immediately with
%!...
--
Pino Toscano