[erlang-questions] Unloading all modules from ERL session

62 views
Skip to first unread message

yas...@gmail.com

unread,
Jun 13, 2013, 3:23:45 AM6/13/13
to erlang-q...@erlang.org

Hi,

If an Erlang session on command prompt is running and I call a function from a module, the module gets loaded. If I realize that there is a bug, and while leaving the erl session running, change the code and recompile the module and amny other modules, the older version of the module remains loaded in teh erl session.

How do I unload all loaded modules so that the newly compiled modules get loaded the next time I invoke the function in the erl session, the new code takes effect?

Thanks,
Yash

Gustav Simonsson

unread,
Jun 13, 2013, 3:30:01 AM6/13/13
to yas...@gmail.com, erlang-q...@erlang.org
Hi,

If this is for development, you may want to look at these two tools:

https://github.com/oinksoft/reloader
https://github.com/rustyio/sync

Cheers,
Gustav


_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


Daniel Goertzen

unread,
Jun 13, 2013, 11:46:20 AM6/13/13
to yas...@gmail.com, Erlang Questions
If it is just 1 or 2 modules, reload those modules with...


1> l(mymodule).
{module,mymodule}
2> 

Dan.


Steve Davis

unread,
Jun 13, 2013, 8:29:40 PM6/13/13
to erlang-pr...@googlegroups.com, erlang-q...@erlang.org
Why not make:all([load]).

???

e.g. I have this in my user_default...

make() ->
{ok, WorkingDir} = file:get_cwd(),
case file:read_file_info("Emakefile") of
{ok, _} -> io:format("Emake ~p~n", [WorkingDir]);
{error, _} -> io:format("~p~n", [WorkingDir])
end,
make:all([load]).


Roberto Aloi

unread,
Jun 14, 2013, 7:11:40 AM6/14/13
to Steve Davis, erlang-pr...@googlegroups.com, Erlang Questions Mailing List

In Erlang, two and only two versions of the same module can coexist in the run time system (an old version and a new version). Processes running the old version of the code will keep running that version (even if you load a new version of the module) until they make a fully qualified call to the module itself (I.e. M:F(A)). If you add a third version of the code in the system (e.g. you load a module twice) the "very old" version gets purged and those processes executing the obsolete version get killed. You can also use code:purge and code:soft_purge to "force" this behaviour. Look at the "code" module for more options.

Steve Davis

unread,
Jun 14, 2013, 8:32:40 PM6/14/13
to erlang-pr...@googlegroups.com, Steve Davis, Erlang Questions Mailing List
Hi Rob,

Good point and awesomely true, and your advice provides invaluable insight into the caution needed when releasing new code to long-running systems in prod (and the need for code change callback implementations). 

However, I've found that during development I rarely need that level of control, so make:all([load]) is more than enough for most purposes in dev that I have faced. 

"as simple as possible, but no simpler"

I guess the trick is to decide what is simple enough for the purpose.

/s
Reply all
Reply to author
Forward
0 new messages