9 def _init(current
, total
):
16 def _wrapped_func(func_and_args
):
17 func
, argument
, should_print_progress
, filter_
= func_and_args
19 if should_print_progress
:
20 with _current
.get_lock():
22 sys
.stdout
.write("\r\t{} of {}".format(_current
.value
, _total
.value
))
25 return func(argument
, filter_
)
29 func
, iterable
, processes
, should_print_progress
, filter_
=None, *args
, **kwargs
32 A parallel map function that reports on its progress.
34 Applies `func` to every item of `iterable` and return a list of the
35 results. If `processes` is greater than one, a process pool is used to run
36 the functions in parallel. `should_print_progress` is a boolean value that
37 indicates whether a string 'N of M' should be printed to indicate how many
38 of the functions have finished being run.
42 _current
= multiprocessing
.Value("i", 0)
43 _total
= multiprocessing
.Value("i", len(iterable
))
45 func_and_args
= [(func
, arg
, should_print_progress
, filter_
) for arg
in iterable
]
47 result
= list(map(_wrapped_func
, func_and_args
, *args
, **kwargs
))
49 pool
= multiprocessing
.Pool(
57 result
= pool
.map(_wrapped_func
, func_and_args
, *args
, **kwargs
)
61 if should_print_progress
:
62 sys
.stdout
.write("\r")