Ask Your Question
0

Why does the method in Python's Pool Map sometimes return certain dictionaries twice?

asked 2021-06-13 11:00:00 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-08-21 19:00:00 +0000

bukephalos gravatar image

The method in Python's Pool Map may return certain dictionaries twice when the input list contains duplicate items. Since the map function is executed in parallel, each worker process may process the same item and return the same result. In this case, the result is duplicated in the output list. One solution to avoid duplicates is to remove the duplicates from the input list before applying the map function. Another solution is to use the Pool's map_async method instead of the map method, which returns the results in the order they were submitted, but this may not be suitable for all use cases.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-06-13 11:00:00 +0000

Seen: 14 times

Last updated: Aug 21 '22