def on_exit(self):
        """
        This method will be called when StaSh is about the be closed.
        """
        self.runtime.save_history()
        self.cleanup()
        # Clear the stack or the stdout becomes unusable for interactive prompt
        self.runtime.worker_registry.purge()

        This method will be called when StaSh is about the be closed.
        
core.py