# Path: lib/workerpool/workers.py
# class Worker(Thread):
#     """
#     A loyal worker who will pull jobs from the `jobs` queue and perform them.
# 
#     The run method will get jobs from the `jobs` queue passed into the
#     constructor, and execute them. After each job, task_done() must be executed
#     on the `jobs` queue in order for the pool to know when no more jobs are
#     being processed.
#     """
# 
#     def __init__(self, jobs):
#         self.jobs = jobs
#         Thread.__init__(self)
# 
#     def run(self):
#         "Get jobs from the queue and perform them as they arrive."
#         while 1:
#             # Sleep until there is a job to perform.
#             job = self.jobs.get()
# 
#             # Yawn. Time to get some work done.
#             try:
#                 job.run()
#                 self.jobs.task_done()
#             except TerminationNotice:
#                 self.jobs.task_done()
#                 break 
# 
# Path: lib/workerpool/jobs.py
# class SimpleJob(Job):
#     """
#     Given a `result` queue, a `method` pointer, and an `args` dictionary or
#     list, the method will execute r = method(*args) or r = method(**args), 
#     depending on args' type, and perform result.put(r).
#     """
#     def __init__(self, result, method, args=[]):
#         self.result = result
#         self.method = method
#         self.args = args
# 
#     def run(self):
#         if isinstance(self.args, list) or isinstance(self.args, tuple):
#             r = self.method(*self.args)
#         elif isinstance(self.args, dict):
#             r = self.method(**self.args)
#         self._return(r)
# 
#     def _return(self, r):
#         "Handle return value by appending to the ``self.result`` queue."
#         self.result.put(r)
# 
# class SuicideJob(Job):
#     "A worker receiving this job will commit suicide."
#     def run(self, **kw):
#         raise TerminationNotice()


from queue import Queue
    from .QueueWrapper import Queue
from .workers import Worker
from .jobs import SimpleJob, SuicideJob
import collections
        for i in range(size):
            self.grow()

    def grow(self):
        "Add another worker to the pool."
        t = self.worker_factory(self)
        t.start()
        self._size += 1

    def shrink(self):
        "Get rid of one worker from the pool. Raises IndexError if empty."
        if self._size <= 0:
            raise IndexError("pool is already empty")
        self._size -= 1
        self.put(SuicideJob())

    def shutdown(self):
        "Retire the workers."
        for i in range(self.size()):
            self.put(SuicideJob())

    def size(self):
        "Approximate number of active workers (could be more if a shrinking is in progress)."
        return self._size

    def map(self, fn, *seq):
        "Perform a map operation distributed among the workers. Will block until done."
        results = Queue()
        args = list(zip(*seq))
        for seq in args:

# Path: lib/workerpool/workers.py
# class Worker(Thread):
#     """
#     A loyal worker who will pull jobs from the `jobs` queue and perform them.
# 
#     The run method will get jobs from the `jobs` queue passed into the
#     constructor, and execute them. After each job, task_done() must be executed
#     on the `jobs` queue in order for the pool to know when no more jobs are
#     being processed.
#     """
# 
#     def __init__(self, jobs):
#         self.jobs = jobs
#         Thread.__init__(self)
# 
#     def run(self):
#         "Get jobs from the queue and perform them as they arrive."
#         while 1:
#             # Sleep until there is a job to perform.
#             job = self.jobs.get()
# 
#             # Yawn. Time to get some work done.
#             try:
#                 job.run()
#                 self.jobs.task_done()
#             except TerminationNotice:
#                 self.jobs.task_done()
#                 break 
# 
# Path: lib/workerpool/jobs.py
# class SimpleJob(Job):
#     """
#     Given a `result` queue, a `method` pointer, and an `args` dictionary or
#     list, the method will execute r = method(*args) or r = method(**args), 
#     depending on args' type, and perform result.put(r).
#     """
#     def __init__(self, result, method, args=[]):
#         self.result = result
#         self.method = method
#         self.args = args
# 
#     def run(self):
#         if isinstance(self.args, list) or isinstance(self.args, tuple):
#             r = self.method(*self.args)
#         elif isinstance(self.args, dict):
#             r = self.method(**self.args)
#         self._return(r)
# 
#     def _return(self, r):
#         "Handle return value by appending to the ``self.result`` queue."
#         self.result.put(r)
# 
# class SuicideJob(Job):
#     "A worker receiving this job will commit suicide."
#     def run(self, **kw):
#         raise TerminationNotice()


# Path: lib/workerpool/pools.py
from queue import Queue
    from .QueueWrapper import Queue
from .workers import Worker
from .jobs import SimpleJob, SuicideJob
import collections

        for i in range(size):
            self.grow()

    def grow(self):
        "Add another worker to the pool."
        t = self.worker_factory(self)
        t.start()
        self._size += 1

    def shrink(self):
        "Get rid of one worker from the pool. Raises IndexError if empty."
        if self._size <= 0:
            raise IndexError("pool is already empty")
        self._size -= 1
        self.put(SuicideJob())

    def shutdown(self):
        "Retire the workers."
        for i in range(self.size()):
            self.put(SuicideJob())

    def size(self):
        "Approximate number of active workers (could be more if a shrinking is in progress)."
        return self._size

    def map(self, fn, *seq):
        "Perform a map operation distributed among the workers. Will block until done."
        results = Queue()
        args = list(zip(*seq))
        for seq in args:

            j = SimpleJob(results, fn, seq)