async def stop(self):
        """Stop all networking and save DB to disk."""
        self.unregister_callbacks()
        try:
            async with ignore_after(5):
                if self.network:
                    if self.lnworker:
                        await self.lnworker.stop()
                        self.lnworker = None
                    self.network = None
                    await self.taskgroup.cancel_remaining()
                    self.taskgroup = None
                await self.adb.stop()
        finally:  # even if we get cancelled
            if any([ks.is_requesting_to_be_rewritten_to_wallet_file for ks in self.get_keystores()]):
                self.save_keystore()
            self.db.prune_uninstalled_plugin_data(self.config.get_installed_plugins())
            self.save_db()
Stop all networking and save DB to disk.
electrum/wallet.py