[erlang-questions] Re: how do I get escript to emit all output before exiting?

Matthias Lang matthias@REDACTED
Mon Apr 4 18:21:52 CEST 2011

On Monday, April 04, Håkan Mattsson wrote:

> The problem is probably that init:stop() returns before all output has
> been emitted.

Yes, that's right. Thanks.

But it's not how I expect escript to behave, i.e. I expect escript to
shut down cleanly by default.

Looking at escript.erl:

  | my_halt(Reason) ->
  |     case process_info(group_leader(), status) of
  |         {_,waiting} ->
  |             %% Now all output data is down in the driver.
  |             %% Give the driver some extra time before halting.
  |             receive after 1 -> ok end,
  |             halt(Reason);
  |         _ ->
  |             %% Probably still processing I/O requests.
  |             erlang:yield(),
  |             my_halt(Reason)
  |     end.

the comments sort-of suggest that it's trying to cleanly shut down.

What IO situation is the code above trying to take care of? Why not just

  my_halt(Reason) ->
     receive after infinity -> ok end.

Not sure if this is a bug or if I'm just expecting too much, but
tossing output by default doesn't seem nice because it leads to code
that seems to work except when it doesn't.


More information about the erlang-questions mailing list