# 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
# workerpool.py - Module for distributing jobs to a pool of worker threads.
# Copyright (c) 2008 Andrey Petrov
#
# This module is part of workerpool and is released under
# the MIT license: http://www.opensource.org/licenses/mit-license.php


if not hasattr(Queue, 'task_done'):
    # Graft Python 2.5's Queue functionality onto Python 2.4's implementation
    # TODO: The extra methods do nothing for now. Make them do something.



__all__ = ['WorkerPool', 'default_worker_factory']


def default_worker_factory(job_queue):

# 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

# workerpool.py - Module for distributing jobs to a pool of worker threads.
# Copyright (c) 2008 Andrey Petrov
#
# This module is part of workerpool and is released under
# the MIT license: http://www.opensource.org/licenses/mit-license.php


if not hasattr(Queue, 'task_done'):
    # Graft Python 2.5's Queue functionality onto Python 2.4's implementation
    # TODO: The extra methods do nothing for now. Make them do something.



__all__ = ['WorkerPool', 'default_worker_factory']


def default_worker_factory(job_queue):

    return Worker(job_queue)