Seth Vidal 1f0fe1a
diff --git a/yum/__init__.py b/yum/__init__.py
Seth Vidal 1f0fe1a
index 6378cdc..cc57e98 100644
Seth Vidal 1f0fe1a
--- a/yum/__init__.py
Seth Vidal 1f0fe1a
+++ b/yum/__init__.py
Seth Vidal 1f0fe1a
@@ -427,6 +427,9 @@ class YumBase(depsolve.Depsolve):
Seth Vidal 1f0fe1a
 
Seth Vidal 1f0fe1a
     def closeRpmDB(self):
Seth Vidal 1f0fe1a
         """closes down the instances of the rpmdb we have wangling around"""
Seth Vidal 1f0fe1a
+        if self._rpmdb is not None:
Seth Vidal 1f0fe1a
+            self._rpmdb.ts = None
Seth Vidal 1f0fe1a
+            self._rpmdb.dropCachedData()
Seth Vidal 1f0fe1a
         self._rpmdb = None
Seth Vidal 1f0fe1a
         self._ts = None
Seth Vidal 1f0fe1a
         self._tsInfo = None
Seth Vidal 1f0fe1a
@@ -1008,6 +1011,7 @@ class YumBase(depsolve.Depsolve):
Seth Vidal 1f0fe1a
         # for any kind of install add from_repo to the yumdb, and the cmdline
Seth Vidal 1f0fe1a
         # and the install reason
Seth Vidal 1f0fe1a
 
Seth Vidal 1f0fe1a
+        self.rpmdb.dropCachedData()
Seth Vidal 1f0fe1a
         for txmbr in self.tsInfo:
Seth Vidal 1f0fe1a
             if txmbr.output_state in TS_INSTALL_STATES:
Seth Vidal 1f0fe1a
                 if not self.rpmdb.contains(po=txmbr.po):
Seth Vidal 1f0fe1a
@@ -1037,7 +1041,7 @@ class YumBase(depsolve.Depsolve):
Seth Vidal 1f0fe1a
             else:
Seth Vidal 1f0fe1a
                 self.verbose_logger.log(logginglevels.DEBUG_2, 'What is this? %s' % txmbr.po)
Seth Vidal 1f0fe1a
 
Seth Vidal 1f0fe1a
-
Seth Vidal 1f0fe1a
+        self.rpmdb.dropCachedData()
Seth Vidal 1f0fe1a
 
Seth Vidal 1f0fe1a
     def costExcludePackages(self):
Seth Vidal 1f0fe1a
         """exclude packages if they have an identical package in another repo
Seth Vidal 4310a2a
Seth Vidal 4310a2a
diff --git a/yum/rpmsack.py b/yum/rpmsack.py
Seth Vidal 4310a2a
index 5189b18..8556e9a 100644
Seth Vidal 4310a2a
--- a/yum/rpmsack.py
Seth Vidal 4310a2a
+++ b/yum/rpmsack.py
Seth Vidal 4310a2a
@@ -140,7 +140,10 @@ class RPMDBPackageSack(PackageSackBase):
Seth Vidal 4310a2a
         self._simple_pkgtup_list = []
Seth Vidal 4310a2a
         self._get_pro_cache = {}
Seth Vidal 4310a2a
         self._get_req_cache = {}
Seth Vidal 4310a2a
-        misc.unshare_data()
Seth Vidal 4310a2a
+        #  We can be called on python shutdown (due to yb.__del__), at which
Seth Vidal 4310a2a
+        # point other modules might not be available.
Seth Vidal 4310a2a
+        if misc is not None:
Seth Vidal 4310a2a
+            misc.unshare_data()
Seth Vidal 4310a2a
         self._cache = {
Seth Vidal 4310a2a
             'provides' : { },
Seth Vidal 4310a2a
             'requires' : { },