Scheduler: PyPy WeakValueDictionary.pop KeyError
authorZac Medico <zmedico@gentoo.org>
Wed, 15 Feb 2012 03:01:16 +0000 (19:01 -0800)
committerZac Medico <zmedico@gentoo.org>
Wed, 15 Feb 2012 03:01:16 +0000 (19:01 -0800)
KeyError observed from WeakValueDictionary.pop() with PyPy 1.8,
despite None given as default. Note that PyPy 1.8 has the same
WeakValueDictionary code as CPython 2.7, so it may be possible for
CPython to raise KeyError here as well.

pym/_emerge/Scheduler.py

index 4b37026675704d803fbd48688864d8d2b5cf772e..c797c32419c70be7ca1e919dcb52c290ee7e27db 100644 (file)
@@ -1620,7 +1620,14 @@ class Scheduler(PollScheduler):
                                        "installed", pkg.root_config, installed=True,
                                        operation="uninstall")
 
-               prefetcher = self._prefetchers.pop(pkg, None)
+               try:
+                       prefetcher = self._prefetchers.pop(pkg, None)
+               except KeyError:
+                       # KeyError observed with PyPy 1.8, despite None given as default.
+                       # Note that PyPy 1.8 has the same WeakValueDictionary code as
+                       # CPython 2.7, so it may be possible for CPython to raise KeyError
+                       # here as well.
+                       prefetcher = None
                if prefetcher is not None and not prefetcher.isAlive():
                        try:
                                self._task_queues.fetch._task_queue.remove(prefetcher)