Revision c258f110 lib/workerpool.py

b/lib/workerpool.py
26 26
import logging
27 27
import threading
28 28
import heapq
29
import itertools
29 30

  
30 31
from ganeti import compat
31 32
from ganeti import errors
......
252 253
    self._termworkers = []
253 254

  
254 255
    # Queued tasks
255
    self._counter = 0
256
    self._counter = itertools.count()
256 257
    self._tasks = []
257 258

  
258 259
    # Start workers
......
279 280
    assert isinstance(args, (tuple, list)), "Arguments must be a sequence"
280 281
    assert isinstance(priority, (int, long)), "Priority must be numeric"
281 282

  
282
    # This counter is used to ensure elements are processed in their
283
    # incoming order. For processing they're sorted by priority and then
284
    # counter.
285
    self._counter += 1
286

  
287
    heapq.heappush(self._tasks, (priority, self._counter, args))
283
    # A counter is used to ensure elements are processed in their incoming
284
    # order. For processing they're sorted by priority and then counter.
285
    heapq.heappush(self._tasks, (priority, self._counter.next(), args))
288 286

  
289 287
    # Notify a waiting worker
290 288
    self._pool_to_worker.notify()

Also available in: Unified diff