[erlang-questions] why call code:purge(Module) twice?

Gijsbert de Haan gijsbert_de_haan@REDACTED
Wed Mar 11 03:55:29 CET 2009


Hi,

To get started with my Erlang server I've scavenged some code from
erlyvideo. So far it has been very helpful, but I am a bit confused
about this code reload function:

reload() ->
    reload([mod1,mod2,mod3]).
reload(Module) when is_atom(Module) ->
    code:purge(Module),
    code:delete(Module),
    code:load_file(Module),
    true;
reload([]) -> ok;
reload([?MODULE | T]) -> reload(T);
reload([H|T]) ->
    reload(H),
    reload(H),
    reload(T).

It reloads the list of modules that make up my server. What I don't
understand is why it calls reload(Module) twice.
If I understand the Erlang documentation correctly calling code:purge()
twice will kill all running erlang processes, making it pretty much a
cold code start.
What would be a reason to do this? I can imagine that sometimes old
processes wouldn't be able to cope with processes running new code, in
which a clean start would be needed. But in that case a graceful stop
and start would be nicer.

Cheers,
Gijsbert





More information about the erlang-questions mailing list