Fix bug in heapq priority queue example.
diff --git a/Doc/library/heapq.rst b/Doc/library/heapq.rst
index 86be3bd..c995802 100644
--- a/Doc/library/heapq.rst
+++ b/Doc/library/heapq.rst
@@ -205,8 +205,8 @@
     def get_top_priority():
         while True:
             priority, count, task = heappop(pq)
-            del task_finder[task]
             if count is not INVALID:
+                del task_finder[task]
                 return task
 
     def delete_task(task):