[erlang-questions] Dynamic code reloading

Igor Ribeiro Sucupira <>
Tue Apr 20 08:31:26 CEST 2010

Once your server is up for the first time, you can use those steps to
update the module after every change in the beam file:
- Call code:soft_purge(dbase).
- Call code:load_file(dbase).
- Send a message {dbase, self(), reload} to the server.


On Tue, Apr 20, 2010 at 12:37 AM, Deryk Barker <> wrote:
> Please excuse me if this is a daft question...and I am sure there are OTP
> functions to do all this for you, but I wanted  to show my students some
> features of "pure" erlang.
> Specifically, I'd like to have a server that can call the latest version of
> itself in response to a message.
> Based on my reading of the "old" erlang book (the OOP, sorry out of print,
> one), it seemed that having a receive pattern something like:
>   {dbase, Pid, reload} ->
>       reply (Pid, reloading),
>       dbase:loop (DataBase);
> would work. (It's a *very* simple database server in a module called dbase).
> Unfortunately, this doesn't cause the new BEAM file, compiled outside the
> erlang shell, to be loaded.
> OK, try compiling in the erlang shell (server is running under same shell),
> but this takes down the server  - silently. I know it's gone because its
> registered name (dbserver) is no longer in the registered name table.
> Perhaps I need to use code:load_file/1?
> But that tells me the module needs to be purged first.
> code:soft_purge/1 (which, according to the documentation, leaves existing
> processes running the module running) fails - with a not_purged error - and
> code:purge/1 works fine, but takes down the server.
> Can anyone tell me how I should be doing this and just how dim I am being?
> thanks,
> deryk
> --
> |Deryk Barker, Computer Science Dept. | Music does not have to be
> understood|
> |Camosun College, Victoria, BC, Canada| It has to be listened to.
> |
> |email:          |
> |
> |phone: +1 250 370 4452               |         Hermann Scherchen.
>  |
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:

"The secret of joy in work is contained in one word - excellence. To
know how to do something well is to enjoy it." - Pearl S. Buck.

More information about the erlang-questions mailing list