To be short,I use python and I have two functions:
def func1(item):
do something
def func2(item):
do something
return result
And I have a list list = [item1, item2, ...]
. Each element is the argument of function func1
and func2
. That is, I want to do the following two loops:
for item in list:
func1(item)
result_list = [func2(item) for item in list]
Now I want to apply threading
and multiprocessing
on these two loops. So what is the easiest way (I mean, in just several lines of codes) to achieve it?
For multiprocessing
on func1
, I like the following code:
with multiprocessing.Pool(processes = 6) as p:
p.imap(func1, list)
Do we have similar code for other cases? That is, threading
on func1
and func2
, multiprocessing
on func2
.