Use Kernel.at_exit hook