[erlang-questions] Re: how do I get escript to emit all output before exiting?
Mon Apr 4 20:06:18 CEST 2011
What about having init:halt() send a sync'd message to the group leader to
Once the group leader shuts down and returns then init:halt() will exit.
Even without a group-leader shutdown, even having the group-leader return a
ping-type message could unblock the init:halt() and ensure that you've
processed the messages at least that far, thus "flushing the buffer."
On Mon, Apr 4, 2011 at 10:24 AM, Scott Lystig Fritchie <
> Matthias Lang <matthias@REDACTED> wrote:
> ml> What IO situation is the code above trying to take care of? Why not
> ml> just
> ml> my_halt(Reason) ->
> ml> init:stop(Reason),
> ml> receive after infinity -> ok
> ml> end.
> ml> Not sure if this is a bug or if I'm just expecting too much, but
> ml> tossing output by default doesn't seem nice because it leads to code
> ml> that seems to work except when it doesn't.
> IIRC the stuff scribbled to the console via io:format() is actually done
> by sending messages to the group leader process. You're at the
> scheduler's whim to decide whether the group leader gets executed &
> processes the I/O requests before the VM halts.
> Having said that, I've been bitten by this same concurrency feature.
> C/Ruby/Python folks don't expect the feature. Even never-touched-
> another-language Erlang hackers may not expect it. But short of having
> a function like like escript:halt/1 to take the place of your my_halt()
> function ... and a whole lot of doc additions to point out that calling
> io:format() is **not** a thin wrapper around the syscall/stdlib calls:
> write(1, str, strlen(str));
> /* OR */
> fwrite(str, strlen(str), 1, stdout);
> ... I can't think of an easier fix. (Perhaps I simply need more
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions