How to set a timeout?

Matthias Huening mhuening at zedat.fu-berlin.de
Wed Jul 18 09:51:51 EDT 2001


I have a function like this:

-----
def read_pages(urllist):
    res = {}
    for x in urllist:
        try:
            res[x] = urllib.urlopen(x).read()
        except:
            pass
    return(res)
-----

I now want the following behaviour: try to catch the webpage for 3 seconds;
if it takes longer just skip this one and move on to the next. How can I
achieve this?

Thanks, Matthias

PS Other suggestions for speeding up the process of reading lets say 100
webpages are welcome...






More information about the Python-list mailing list