Permalink
Browse files

Added round robin iterator

  • Loading branch information...
1 parent 07a1a6c commit 4ff565b0e3e894352ff458fb6e3b30f237b33a3b Kevin Landreth committed Nov 29, 2012
Showing with 17 additions and 0 deletions.
  1. +17 −0 slbackup.py
View
@@ -21,6 +21,7 @@
from copy import copy
from hashlib import md5
from multiprocessing import Manager, Pool, cpu_count, TimeoutError
+from itertools import repeat
import Queue
try:
@@ -709,6 +710,22 @@ def queue_iter(queue):
yield item
+def roundrobin_iter(**queues):
+ total_queues = len(queues)
+ miss = 0
+ for name, q in repeat(queues.iteritems()):
+ try:
+ item = q.get(False)
+ except (Queue.Empty, TimeoutError):
+ miss += 1
+ if miss > total_queues:
+ break
+ continue
+ else:
+ miss = 0
+ yield name, item
+
+
class IterUnwrap(object):
def __init__(self, func, *args, **kwargs):
self.func = func

0 comments on commit 4ff565b

Please sign in to comment.