# Path: src/TubeQ.py
# class TubeQ:
#     """A unidirectional communication channel 
#     using :class:`multiprocessing.Queue` for underlying implementation."""
# 
#     def __init__(self, maxsize=0):
#         self._queue = multiprocessing.Queue(maxsize)
# 
#     def put(self, data):
#         """Put an item on the tube."""
#         self._queue.put(data)
# 
#     def get(self, timeout=None):
#         """Return the next available item from the tube.
# 
#         Blocks if tube is empty, until a producer for the tube puts an item on it."""
#         if timeout:
#             try:
#                 result = self._queue.get(True, timeout)
#             except multiprocessing.Queue.Empty:
#                 return(False, None)
#             return(True, result)
#         return self._queue.get()


import multiprocessing
from .TubeQ import TubeQ
    publishing its result whenever it is done
    (without coordinating with neighboring workers).
    Consequently, the order of output results may not match 
    that of corresponding input tasks."""

    def __init__(self):
        pass

    def init2(
        self, 
        input_tube,      # Read task from the input tube.
        output_tubes,    # Send result on all the output tubes.
        num_workers,     # Total number of workers in the stage.
        disable_result,  # Whether to override any result with None.
        do_stop_task,    # Whether to call doTask() on "stop" request.
        ):
        """Create *num_workers* worker objects with *input_tube* and 
        an iterable of *output_tubes*. The worker reads a task from *input_tube* 
        and writes the result to *output_tubes*."""

        super(UnorderedWorker, self).__init__()
        self._tube_task_input = input_tube
        self._tubes_result_output = output_tubes
        self._num_workers = num_workers
        self._disable_result = disable_result
        self._do_stop_task = do_stop_task

    @staticmethod
    def getTubeClass():
        """Return the tube class implementation."""

# Path: src/TubeQ.py
# class TubeQ:
#     """A unidirectional communication channel 
#     using :class:`multiprocessing.Queue` for underlying implementation."""
# 
#     def __init__(self, maxsize=0):
#         self._queue = multiprocessing.Queue(maxsize)
# 
#     def put(self, data):
#         """Put an item on the tube."""
#         self._queue.put(data)
# 
#     def get(self, timeout=None):
#         """Return the next available item from the tube.
# 
#         Blocks if tube is empty, until a producer for the tube puts an item on it."""
#         if timeout:
#             try:
#                 result = self._queue.get(True, timeout)
#             except multiprocessing.Queue.Empty:
#                 return(False, None)
#             return(True, result)
#         return self._queue.get()


# Path: src/UnorderedWorker.py
import multiprocessing
from .TubeQ import TubeQ

    publishing its result whenever it is done
    (without coordinating with neighboring workers).
    Consequently, the order of output results may not match 
    that of corresponding input tasks."""

    def __init__(self):
        pass

    def init2(
        self, 
        input_tube,      # Read task from the input tube.
        output_tubes,    # Send result on all the output tubes.
        num_workers,     # Total number of workers in the stage.
        disable_result,  # Whether to override any result with None.
        do_stop_task,    # Whether to call doTask() on "stop" request.
        ):
        """Create *num_workers* worker objects with *input_tube* and 
        an iterable of *output_tubes*. The worker reads a task from *input_tube* 
        and writes the result to *output_tubes*."""

        super(UnorderedWorker, self).__init__()
        self._tube_task_input = input_tube
        self._tubes_result_output = output_tubes
        self._num_workers = num_workers
        self._disable_result = disable_result
        self._do_stop_task = do_stop_task

    @staticmethod
    def getTubeClass():
        """Return the tube class implementation."""

        return TubeQ