questions about multiprocessing

Vincent Ren renws1990 at gmail.com
Sat Mar 5 04:29:30 EST 2011


Got it.
After putting commas, it works (The 'o' was a mistake when I posted,
sorry about it ).

Thanks to all of you :)


On Mar 5, 5:12 pm, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> On Fri, 4 Mar 2011 20:08:21 -0800 (PST), Vincent Ren
> <renws1... at gmail.com> declaimed the following in
> gmane.comp.python.general:
>
> > Hello, everyone, recently I am trying to learn python's
> > multiprocessing, but
> > I got confused as a beginner.
>
> > If I run the code below:
>
> > from multiprocessing import Pool
> > import urllib2
> > otasks = [
> >      'http://www.php.net'
> >      'http://www.python.org'
> >      'http://www.perl.org'
> >      'http://www.gnu.org'
> >      ]
>
>         You've just defined a list with ONE element -- a string of:
>
> "http://www.php.nethttp://www.python.orghttp://www.perl.orghttp://http..."
>
>         Python concatenates adjacent strings -- which includes those on
> multiple lines when inside an open ( [ { structure.
>
>         You need to put commas after the closing quotes on those lines.
>
> > def f(url):
> >      return urllib2.urlopen(url).read()
>
> > pool = Pool(processes = 2)
> > print pool.map(f, tasks)
>
>         And I'm presuming the others are correct -- and that should be
>
> (f, otasks)
>
> > httplib.InvalidURL: nonnumeric port: ''
>
>         No surprise... URL nomenclature expects a port number after the
> second : in URL, and with concatenation you've got four : in a single
> URL.
> --
>         Wulfraed                 Dennis Lee Bieber         AF6VN
>         wlfr... at ix.netcom.com    HTTP://wlfraed.home.netcom.com/




More information about the Python-list mailing list