[erlang-questions] How to upgrade runningapplications repeatedly
Ulf Wiger (TN/EAB)
ulf.wiger@REDACTED
Fri Jun 8 08:39:23 CEST 2007
Matthias Lang wrote:
>
> Roger Larsson writes:
> > I think that this is your problem
> >
> > On Thursday 07 June 2007 22:06, Bo wrote:
> > > start_server(L) ->
> > > process_flag(trap_exit, true),
> > > register(test,
> > > spawn(fun() ->
> > > process_flag(trap_exit, true),
> > > Val= (catch ?MODULE:server_loop([L])),
> > > io:format("Server terminated with:~p~n",[Val])
> > > end)).
> >
> > This one function that will not upgrade itself. Requiring
> the > original version to remain in memory.
>
> You're right, I missed that.
>
> > Simple test move this part to another module.
> > (But I think the real solution would be to use spawn_link)
>
> spawn_link on its own will make the problem more obvious, but
> it won't make it go away.
Instead of writing
Val = (catch ?MODULE:server_loop([L])),
one can use proc_lib:spawn(fun() -> ... end)
With SASL running, this will give a crash report if the
process terminates with Reason =/= normal.
Here's the relevant code from proc_lib.erl:
init_p(Parent,Ancestors,F) when function(F) ->
put('$ancestors',[Parent|Ancestors]),
put('$initial_call',F),
Result = (catch F()),
exit_p(Result,F).
exit_p({'EXIT',Reason},StartF) ->
crash_report(Reason,StartF),
exit(Reason);
exit_p(Reason,_) ->
Reason.
BR,
Ulf W
More information about the erlang-questions
mailing list