def multiprocess_with_queues(nproc, func, inputs, verbose=False,<EOL>**progress_kw):
if nproc != <NUM_LIT:1> and os.name == '<STR_LIT>':<EOL><INDENT>warnings.warn(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>nproc = <NUM_LIT:1><EOL><DEDENT>if progress_kw.pop('<STR_LIT>', None) is not None:<EOL><INDENT>warnings.warn("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>", DeprecationWarning)<EOL><DEDENT>if bool(verbose):<EOL><INDENT>if not isinstance(verbose, bool):<EOL><INDENT>progress_kw['<STR_LIT>'] = str(verbose)<EOL><DEDENT>if isinstance(inputs, (list, tuple)):<EOL><INDENT>progress_kw.setdefault('<STR_LIT>', len(inputs))<EOL><DEDENT>pbar = progress_bar(**progress_kw)<EOL><DEDENT>else:<EOL><INDENT>pbar = None<EOL><DEDENT>def _inner(x):<EOL><INDENT>"""<STR_LIT>"""<EOL>try:<EOL><INDENT>return func(x)<EOL><DEDENT>except Exception as exc:  <EOL><INDENT>if nproc == <NUM_LIT:1>:<EOL><INDENT>raise<EOL><DEDENT>return exc<EOL><DEDENT>finally:<EOL><INDENT>if pbar and nproc == <NUM_LIT:1>:<EOL><INDENT>pbar.update()<EOL><DEDENT><DEDENT><DEDENT>if nproc == <NUM_LIT:1>:<EOL><INDENT>return list(map(_inner, inputs))<EOL><DEDENT>q_in = Queue()<EOL>q_out = Queue()<EOL>proclist = [Process(target=process_in_out_queues,<EOL>args=(_inner, q_in, q_out)) for _ in range(nproc)]<EOL>for proc in proclist:<EOL><INDENT>proc.daemon = True<EOL>proc.start()<EOL><DEDENT>sent = [q_in.put(x, block=False) for x in enumerate(inputs)]<EOL>for _ in range(nproc):  <EOL><INDENT>q_in.put((None, None))<EOL><DEDENT>res = []<EOL>for _ in range(len(sent)):<EOL><INDENT>x = q_out.get()<EOL>if pbar:<EOL><INDENT>pbar.update()<EOL><DEDENT>res.append(x)<EOL><DEDENT>for proc in proclist:<EOL><INDENT>proc.join()<EOL><DEDENT>if pbar:<EOL><INDENT>pbar.close()<EOL><DEDENT>results = [out for _, out in sorted(res, key=itemgetter(<NUM_LIT:0>))]<EOL>for res in results:<EOL><INDENT>if isinstance(res, Exception):<EOL><INDENT>raise res<EOL><DEDENT><DEDENT>return results<EOL>
Map a function over a list of inputs using multiprocess

    This essentially duplicates `multiprocess.map` but allows for
    arbitrary functions (that aren't necessarily importable)

    Parameters
    ----------
    nproc : `int`
        number of processes to use, if ``1`` is given, the current process
        is used, and no child processes are forked

    func : `callable`
        the function to call in each iteration, should take a single
        argument that is the next element from ``inputs``

    inputs : `iterable`
        iterable (e.g. `list`) of inputs, each element of which is
        passed to ``func`` in one of the child processes

    verbose : `bool`, `str`, optional
        if `True`, print progress to the console as a bar, pass a
        `str` to customise the heading for the progress bar, default: `False`,
        (default heading ``'Processing:'`` if ``verbose=True`)

    Returns
    -------
    outputs : `list`
        the `list` of results from calling ``func(x)`` for each element
        of ``inputs``