late on_loads on init

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

late on_loads on init

Xavier Noria
I have observed that on_load handlers happen late in the init process.

I would have expected that an on_load handler ran when the module is loaded into the VM as primLoads are processed.

But, it turns out they do not run at that point. Before on load handlers run, all applications are loaded, and kernel started. Only later does the hook get executed, and boot continues starting the rest of applications.

In a production Distilley release for example (embedded mode, in particular), this is easy to see passing ERL_OPTS=-init_debug to a command. You'll see {`running_on_load_handler`, Module} printed when the hook is invoked.

Two questions here:

1) Is this done because starting kernel is needed to have a minimum of things setup in order to run code, do I/O etc. in the on_load handler? If yes, is application:load/1 carefully written to not depend on such setup? (since it runs before kernel starts).

2) On the other hand, if you load a module on demand in interactive mode, the hook is executed right away. That says primLoad has to load modules in a different way somehow. Do you know which is the difference?

erlang-questions mailing list
[hidden email]