executor.map() TypeError: zip argument #2 must support iteration

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Apr 1 03:48:34 EDT 2013


On Sun, 31 Mar 2013 21:45:21 -0700, iMath wrote:

> executor.map()    TypeError: zip argument #2 must support iteration
> 
> when I run it ,just generated TypeError: zip argument #2 must support
> iteration. can anyone help me fix this problem ?

Yes. Read the error message, and inspect the line that is in error. You 
have:

>     future_to_url = executor.map(str,lst100, 60)

executor.map has three arguments:

Arg 0: str
Arg 1: list of 100 ints
Arg 2: int 60

Argument 2, the number 60, does not support iteration, since it is an int.

Now read the docs for map. At the interactive interpreter, do this:

py> from concurrent.futures import ThreadPoolExecutor
py> help(ThreadPoolExecutor.map)


and you will see the following documentation:

map(self, fn, *iterables, timeout=None)
    Returns a iterator equivalent to map(fn, iter).

    Args:
        fn: A callable that will take take as many arguments as there are
            passed iterables.
        timeout: The maximum number of seconds to wait. If None, then
            there is no limit on the wait time.


Notice that the iterables argument is prefixed with * symbol. That means 
that it collects all the remaining positional arguments, which means that 
the timeout argument is keyword only.

So try this:


future_to_url = executor.map(str, lst100, timeout=60)


-- 
Steven



More information about the Python-list mailing list