f



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

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 ?

import time, concurrent.futures
lst100=[i for i in range(100)]

t1=time.clock()
print(list(map(str,lst100)))
t2=time.clock()
print(t2-t1)

t3=time.clock()
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
    future_to_url = executor.map(str,lst100, 60)
    print(list(future_to_url))
t4=time.clock()
print(t4-t3)
0
iMath
4/1/2013 4:45:21 AM
comp.lang.python 77058 articles. 6 followers. Post Follow

2 Replies
4538 Views

Similar Articles

[PageSpeed] 27

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
0
4/1/2013 7:48:34 AM
=E5=9C=A8 2013=E5=B9=B44=E6=9C=881=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=80UTC+8=
=E4=B8=8B=E5=8D=883=E6=97=B648=E5=88=8634=E7=A7=92=EF=BC=8CSteven D'Aprano=
=E5=86=99=E9=81=93=EF=BC=9A
> On Sun, 31 Mar 2013 21:45:21 -0700, iMath wrote:
>=20
>=20
>=20
> > executor.map()    TypeError: zip argument #2 must support iteration
>=20
> >=20
>=20
> > when I run it ,just generated TypeError: zip argument #2 must support
>=20
> > iteration. can anyone help me fix this problem ?
>=20
>=20
>=20
> Yes. Read the error message, and inspect the line that is in error. You=
=20
>=20
> have:
>=20
>=20
>=20
> >     future_to_url =3D executor.map(str,lst100, 60)
>=20
>=20
>=20
> executor.map has three arguments:
>=20
>=20
>=20
> Arg 0: str
>=20
> Arg 1: list of 100 ints
>=20
> Arg 2: int 60
>=20
>=20
>=20
> Argument 2, the number 60, does not support iteration, since it is an int=
..
>=20
>=20
>=20
> Now read the docs for map. At the interactive interpreter, do this:
>=20
>=20
>=20
> py> from concurrent.futures import ThreadPoolExecutor
>=20
> py> help(ThreadPoolExecutor.map)
>=20
>=20
>=20
>=20
>=20
> and you will see the following documentation:
>=20
>=20
>=20
> map(self, fn, *iterables, timeout=3DNone)
>=20
>     Returns a iterator equivalent to map(fn, iter).
>=20
>=20
>=20
>     Args:
>=20
>         fn: A callable that will take take as many arguments as there are
>=20
>             passed iterables.
>=20
>         timeout: The maximum number of seconds to wait. If None, then
>=20
>             there is no limit on the wait time.
>=20
>=20
>=20
>=20
>=20
> Notice that the iterables argument is prefixed with * symbol. That means=
=20
>=20
> that it collects all the remaining positional arguments, which means that=
=20
>=20
> the timeout argument is keyword only.
>=20
>=20
>=20
> So try this:
>=20
>=20
>=20
>=20
>=20
> future_to_url =3D executor.map(str, lst100, timeout=3D60)
>=20
>=20
>=20
>=20
>=20
> --=20
>=20
> Steven

thanks for  clarification.I thought argument 2 is lst100
0
iMath
4/3/2013 2:34:25 AM
Reply:

Web resources about - executor.map() TypeError: zip argument #2 must support iteration - comp.lang.python

Resources last updated: 3/10/2016 7:04:15 AM