[erlang-questions] Re: how do I get escript to emit all output before exiting?
Scott Lystig Fritchie
Mon Apr 4 19:24:39 CEST 2011
Matthias Lang <matthias@REDACTED> wrote:
ml> What IO situation is the code above trying to take care of? Why not
ml> my_halt(Reason) ->
ml> receive after infinity -> ok
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
More information about the erlang-questions