Dynamic code reloading

Deryk Barker <>
Tue Apr 20 05:37:22 CEST 2010


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.          |




More information about the erlang-questions mailing list