Handle KeyError due to stale events.
authorZac Medico <zmedico@gentoo.org>
Fri, 13 Aug 2010 19:33:48 +0000 (12:33 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 13 Aug 2010 19:33:48 +0000 (12:33 -0700)
pym/_emerge/PollScheduler.py

index 704ddc3171a387436710ed883a1e0c2196782d50..ea8ebaacf041ece9aeb2c0644cf08fb0f4f57ba8 100644 (file)
@@ -161,9 +161,13 @@ class PollScheduler(object):
                try:
                        while event_handlers and self._poll_event_queue:
                                f, event = self._next_poll_event()
-                               handler, reg_id = event_handlers[f]
-                               handler(f, event)
-                               events_handled += 1
+                               try:
+                                       handler, reg_id = event_handlers[f]
+                               except KeyError:
+                                       pass
+                               else:
+                                       handler(f, event)
+                                       events_handled += 1
                except StopIteration:
                        events_handled += 1
 
@@ -210,9 +214,13 @@ class PollScheduler(object):
                try:
                        while wait_ids.intersection(handler_ids):
                                f, event = self._next_poll_event(timeout=timeout)
-                               handler, reg_id = event_handlers[f]
-                               handler(f, event)
-                               event_handled = True
+                               try:
+                                       handler, reg_id = event_handlers[f]
+                               except KeyError:
+                                       pass
+                               else:
+                                       handler(f, event)
+                                       event_handled = True
                                if timeout is not None:
                                        if 1000 * time.time() - start_time >= timeout:
                                                break