Skip to content

multiprocessing.pool: Fix return of map_async()#3378

Merged
srittau merged 2 commits intopython:masterfrom
semgrep:nbrahms/fix_map_async_return_type
Oct 17, 2019
Merged

multiprocessing.pool: Fix return of map_async()#3378
srittau merged 2 commits intopython:masterfrom
semgrep:nbrahms/fix_map_async_return_type

Conversation

@nbrahms
Copy link
Contributor

@nbrahms nbrahms commented Oct 17, 2019

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.

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.
Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@nbrahms
Copy link
Contributor Author

nbrahms commented Oct 17, 2019

Hi @srittau ... I just looked at the multiprocessing.pool code again, and I agree with you:

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] * length

I've updated the PR per your request.

@nbrahms nbrahms requested a review from srittau October 17, 2019 15:01
@srittau srittau merged commit fa9e1ab into python:master Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants