Fix #7282 by replacing the shutdown_hook with the atexit module.