# Path: generators/chunks.py
# def chunks(stream, *chunk_sizes, output_type=tuple):
#     ''' yields a stream chunked at a specific size
#         if given multiple sizes the chunks are multidimentional
#     '''
#     assert iterable(stream), 'chunks needs stream to be iterable'
#     for size in chunk_sizes:
#         assert (isinstance(size, int) and size > 0) or callable(size), 'chunks needs chunk_size to be a positive int or callable'
#     assert callable(output_type), 'chunks needs output_type to be callable'
#     
#     for size in chunk_sizes:
#         stream = _chunks(
#             stream,
#             size,
#             output_type=output_type
#         )
#         
#     yield from stream


from multiprocessing import Pool
from multiprocessing.pool import ThreadPool
from queue import Queue
from .chunks import chunks
    import random, time


__all__ = 'map_parallel', 'map_multicore', 'map_multithread'

def _pool_map_stream(pool_type, pipe, fn, workers):
    assert callable(fn), fn
    assert isinstance(workers, int), workers
    assert workers > 0, workers
    p = pool_type(workers)

# Path: generators/chunks.py
# def chunks(stream, *chunk_sizes, output_type=tuple):
#     ''' yields a stream chunked at a specific size
#         if given multiple sizes the chunks are multidimentional
#     '''
#     assert iterable(stream), 'chunks needs stream to be iterable'
#     for size in chunk_sizes:
#         assert (isinstance(size, int) and size > 0) or callable(size), 'chunks needs chunk_size to be a positive int or callable'
#     assert callable(output_type), 'chunks needs output_type to be callable'
#     
#     for size in chunk_sizes:
#         stream = _chunks(
#             stream,
#             size,
#             output_type=output_type
#         )
#         
#     yield from stream


# Path: generators/map_parallel.py
from multiprocessing import Pool
from multiprocessing.pool import ThreadPool
from queue import Queue
from .chunks import chunks
    import random, time



__all__ = 'map_parallel', 'map_multicore', 'map_multithread'

def _pool_map_stream(pool_type, pipe, fn, workers):
    assert callable(fn), fn
    assert isinstance(workers, int), workers
    assert workers > 0, workers
    p = pool_type(workers)

    job_q = Queue(maxsize=int(workers*2))