multiprocessing.pool: Fix return of map_async()#3378
Merged
srittau merged 2 commits intopython:masterfrom Oct 17, 2019
semgrep:nbrahms/fix_map_async_return_type
Merged
multiprocessing.pool: Fix return of map_async()#3378srittau merged 2 commits intopython:masterfrom semgrep:nbrahms/fix_map_async_return_type
srittau merged 2 commits intopython:masterfrom
semgrep:nbrahms/fix_map_async_return_type
Conversation
This commit fixes the issue raised in #3377. Inspecting the multiprocessing code, it appears that MapResult is a minimal extension of AsyncResult, so I choose to remove the extra List[] type from its generic argument (alternatively one could remove it from the return type of map_async() itself, but this seems incorrect as map() has a return type of List[]). The multiprocessing.pool API appears not to have changed at least since 2.7, so this change should work for both Python 2 and 3.
srittau
requested changes
Oct 17, 2019
Collaborator
srittau
left a comment
There was a problem hiding this comment.
Thanks! I think it would make more sense to leave MapResult unchanged, since MapResults always use list values for ApplyResult. Instead, remove the spurious List from map_async()'s return type.
On returning to the multiprocessing.pool code, I see that MapResult does indeed always return a List type. Therefore, to fix the doubly nested list in multiprocessing.pool.map_async, we should remove the spurious List type from the map_async def instead.
Contributor
Author
|
Hi @srittau ... I just looked at the class MapResult(ApplyResult):
def __init__(self, cache, chunksize, length, callback, error_callback):
ApplyResult.__init__(self, cache, callback,
error_callback=error_callback)
self._success = True
self._value = [None] * lengthI've updated the PR per your request. |
srittau
approved these changes
Oct 17, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit fixes the issue raised in
#3377.
Inspecting the multiprocessing code, it appears that MapResult is
a minimal extension of AsyncResult, so I choose to remove the extra
List[] type from its generic argument (alternatively one could remove it
from the return type of map_async() itself, but this seems incorrect as
map() has a return type of List[]).
The multiprocessing.pool API appears not to have changed at least since
2.7, so this change should work for both Python 2 and 3.