Running code when a script exits

BTW, if you do not call System.stop/1 and let run/1 and the script finish by itself, then System.at_exit/1 gets invoked, but the application is apparently not stopped. At least, I do not see terminate/2 callbacks being invoked.