[erlang-questions] When is code_change triggered?

tsuraan tsuraan@REDACTED
Thu Jun 26 18:05:25 CEST 2008


When I started playing with gen_server a few years ago, I recalled
that doing a c(module) in the REPL would immediately update the code
of my running servers.  Now, I cannot get that to happen, so I'm
trying to figure out what I'm doing wrong.  My test server is minimal:

-module(test).
-export([start_link/0, start/0]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
         terminate/2, code_change/3]).

start_link() ->
  gen_server:start_link({ local, ?MODULE }, ?MODULE, [], []).

start() ->
  gen_server:start({ local, ?MODULE }, ?MODULE, [], []).

init([]) ->
  process_flag(trap_exit, true),
  { ok, {}}.

handle_call(Msg, From, State) ->
  io:format("Unexpected Call ~p From ~p~n", [Msg, From]),
  { reply, { error, badcall }, State }.

handle_cast(Msg, State) ->
  io:format("Unexpected Cast ~p~n", [Msg]),
  { noreply, State }.

handle_info(Msg, State) ->
  io:format("Unexpected Info ~p~n", [Msg]),
  { noreply, State }.

terminate(Reason, _State) ->
  io:format("Terminating ~p for reason ~p~n", [ self(), Reason ]),
  ok.

code_change(OldVsn, State, Extra) ->
  io:format("Upgrading from ~p with extra data ~p~n", [OldVsn, Extra]),
  { ok, State }.

I can run this with test:start(), but subsequent c(test) never print
the message "Upgrading from ...".  Can anyone tell what I'm doing
wrong, or is my memory just bad and c(module) has never caused running
instances of that module to be upgraded?



More information about the erlang-questions mailing list