Bug 875025. Use a deque, not a list, for the pending queue in pymake. r=glandium
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 23 May 2013 11:53:25 -0400
changeset 344 211b0c4298e3
parent 343 9a7fff5332b0
child 345 4502b185d064
push id217
push userbzbarsky@mozilla.com
push dateThu, 23 May 2013 15:53:45 +0000
reviewersglandium
bugs875025
Bug 875025. Use a deque, not a list, for the pending queue in pymake. r=glandium
pymake/process.py
--- a/pymake/process.py
+++ b/pymake/process.py
@@ -1,16 +1,17 @@
 """
 Skipping shell invocations is good, when possible. This wrapper around subprocess does dirty work of
 parsing command lines into argv and making sure that no shell magic is being used.
 """
 
 #TODO: ship pyprocessing?
 import multiprocessing
 import subprocess, shlex, re, logging, sys, traceback, os, imp, glob
+from collections import deque
 # XXXkhuey Work around http://bugs.python.org/issue1731717
 subprocess._cleanup = lambda: None
 import command, util
 if sys.platform=='win32':
     import win32process
 
 _log = logging.getLogger('pymake.process')
 
@@ -434,30 +435,30 @@ class ParallelContext(object):
     _allcontexts = set()
     _condition = multiprocessing.Condition()
 
     def __init__(self, jcount):
         self.jcount = jcount
         self.exit = False
 
         self.processpool = multiprocessing.Pool(processes=jcount)
-        self.pending = [] # list of (cb, args, kwargs)
+        self.pending = deque() # deque of (cb, args, kwargs)
         self.running = [] # list of (subprocess, cb)
 
         self._allcontexts.add(self)
 
     def finish(self):
         assert len(self.pending) == 0 and len(self.running) == 0, "pending: %i running: %i" % (len(self.pending), len(self.running))
         self.processpool.close()
         self.processpool.join()
         self._allcontexts.remove(self)
 
     def run(self):
         while len(self.pending) and len(self.running) < self.jcount:
-            cb, args, kwargs = self.pending.pop(0)
+            cb, args, kwargs = self.pending.popleft()
             cb(*args, **kwargs)
 
     def defer(self, cb, *args, **kwargs):
         assert self.jcount > 1 or not len(self.pending), "Serial execution error defering %r %r %r: currently pending %r" % (cb, args, kwargs, self.pending)
         self.pending.append((cb, args, kwargs))
 
     def _docall_generic(self, pool, job, cb, echo, justprint):
         if echo is not None: