On Fri, 4 Mar 2011 20:08:21 -0800 (PST), Vincent Ren
<> 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://www.gnu.org"
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
HTTP://wlfraed.home.netcom.com/