Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I have not seen clear examples with use-cases for Pool.apply, Pool.apply_async and Pool.map. I am mainly using Pool.map; what are the advantages of others?

1 Answer

0 votes
by (106k points)

You can use pool.apply(f, args):  in the argument, the f is only executed in one of the workers of the pool. So one of the processes in the pool will run f(args).

The Pool.apply_async method has a callback which, if supplied, is called when the function is complete. This can be used instead of calling get().

Whereas pool.map(f, iterable) chops the iterable into a number of chunks which it submits to the process pool as separate tasks. So you take advantage of all the processes in the pool.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jun 27, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jun 27, 2019 in Python by Sammy (47.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...