code: def closing_plugin(self, cancelable=False):
          
          self.mainwindow_close = True
          for client in self.clients:
              client.shutdown()
              client.remove_stderr_file()
              client.dialog_manager.close_all()
              client.close()
          return True
docs: Perform actions before parent main window is closed