[erlang-questions] Hot code replacement issues ?
Taavi Talvik
taavi@REDACTED
Wed Dec 14 11:34:57 CET 2016
Switch to new version of code happens, when fully qualified
function is called:
1) Switch to new code version happens:
loop(..) ->
modulename:loop().
2) Old code will remain in use:
loop(..) ->
loop().
best regards,
taavi
> On 14 Dec 2016, at 12:28, Alex Feng <sweden.feng@REDACTED> wrote:
>
> Hi Erlangers,
>
> I am trying to understand how hot patch upgrade is done in Erlang, I got this piece of code from stackoverflow, but I ran into 2 issues when I played around with it.
>
> Issue 1) In the piece of code, I suppose to send a message 'upgrade' to the running process, then it will finish the upgrade. It is working fine with "?MODULE:loop();", but if I remove the prefix ?MODULE in the code, then the upgrade will be failed, I mean when I send message 'run' after upgrade neither the new message nor the old message are printed.
>
> Issue 2) I was told if I recompile and reload the updated file from shell, then it will be done as well.
> So, I did this from shell, update the source file -> compile the file -> reload it ->send msg 'run' to the same process -> 'new version' is not printed out. What could be the mistake?
>
>
>
> -module(test_hot_swap).
>
> -export([loop/0]).
>
> loop() ->
> receive
> upgrade ->
> code:purge(?MODULE),
> compile:file(?MODULE),
> code:load_file(?MODULE),
> ?MODULE:loop(); %%without ?MODULE, it has problem.
> run ->
> io:format("This is a new version ~n"), %% before upgrade, the text is 'old version'.
> loop();
> _ ->
> loop()
> end.
>
> Thank you.
>
> Br,
> Alex
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
—
The single biggest problem in communication is the illusion that it has taken place. (George Bernard Shaw)
More information about the erlang-questions
mailing list