[erlang-questions] Dynamic code reloading

Jeffm jeffm@REDACTED
Tue Apr 20 06:11:30 CEST 2010


When you loaded the new module in the shell did you use c() or l(dbase)? 
If you compiled external to the shell, as you stated, you'll need to use 
l(module_name) to tell the shell to load the new version.

Jeff.

On 20/04/10 1:37 PM, 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
>



More information about the erlang-questions mailing list