On 15/10/12 05:05, Norman Khine wrote:

for page_no in pages:
[...]
        try:
                urllib2.urlopen(req)
        except urllib2.URLError, e:
                pass
        else:
                # do something with the page
                doc = urllib2.urlopen(req)

This is a bug. Just because urlopen(req) succeeded a moment ago, doesn't mean
that it will necessarily succeed now.

This is an example of the general class of bug known as a "race condition":

http://en.wikipedia.org/wiki/Race_condition


Better to write this as:


try:
    doc = urllib2.urlopen(req)
except urllib2.URLError, e:
    pass
else:
    # do something with the page
    [rest of code goes here]




--
Steven
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to