[erlang-questions] module_info and code switch

Fred Youhanaie fly@REDACTED
Tue Nov 26 20:43:09 CET 2013


Hi

I'm playing with a simple piece of code where I switch versions via erl shell.

Curiously I noticed that as soon as I load a new version of the module, module_info/1 returns the attribute of the currently loaded version rather than the version for the running process!

Is this intentional?

Code and sample session is at the bottom.

Thanks

Fred

Here's the code:

-module(loopie).
-compile([export_all]).
start() ->
	start(5000).
start(T) ->
	register(loopie, spawn(?MODULE, loop, [T])).
loop(T) ->
	receive
		switch ->
			io:format("switched~n"),
			loopie:loop(T);
		ANY	->
			io:format("received unexpected message >~p<.~n", [ANY]),
			loop(T)
	after T	->
		io:format("v1 ~p.~n", [module_info(attributes)]),
		loop(T)
	end.

Here's a sample session:

1. initially loopie prints v1 and vsn every 5 seconds.
2. on the source "v1" is changed to "v2" and module is compiled and loaded
3. loopie is now printing v1 but with the new vsn
4. switch message is sent
5. loopie is now printing v2 and the new vsn

$ erl
Erlang R16B02 (erts-5.10.3) [source] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V5.10.3  (abort with ^G)
1> l(loopie).
{module,loopie}
2> loopie:start().
true
v1 [{vsn,[102112148784636006663528886950745967476]}].
v1 [{vsn,[102112148784636006663528886950745967476]}].
3> l(loopie).
{module,loopie}
v1 [{vsn,[337256366447556252629333013282189761649]}].
v1 [{vsn,[337256366447556252629333013282189761649]}].
v1 [{vsn,[337256366447556252629333013282189761649]}].
4> loopie!switch.
switched
switch
v2 [{vsn,[337256366447556252629333013282189761649]}].
v2 [{vsn,[337256366447556252629333013282189761649]}].
5>



More information about the erlang-questions mailing list