python - Using urllib2.urlopen() to load a URL without waiting for a response -
i want send request don't want waste time waiting responses. because responses useless me. looked python doc didn't find solution. advice. have tried use urllib2.urlopen(url, timeout=0.02)
can't sure if request sent out.
this called asynchronous loading, , here's blog post explaining how urllib2. sample code:
#!/usr/bin/env python import urllib2 import threading class myhandler(urllib2.httphandler): def http_response(self, req, response): print "url: %s" % (response.geturl(),) print "info: %s" % (response.info(),) l in response: print l return response o = urllib2.build_opener(myhandler()) t = threading.thread(target=o.open, args=('http://www.google.com/',)) t.start() print "i'm asynchronous!"
this load url without waiting response.
Comments
Post a Comment