mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Merged revisions 80256 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
  r80256 | senthil.kumaran | 2010-04-20 16:05:49 +0530 (Tue, 20 Apr 2010) | 9 lines
  Merged revisions 80236 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk
  ........
    r80236 | senthil.kumaran | 2010-04-20 12:24:59 +0530 (Tue, 20 Apr 2010) | 3 lines
    Fix Issue8460: Victor's patch to add timeout in test_urllib2net test_urls.
  ........
................
			
			
This commit is contained in:
		
							parent
							
								
									f2e330a9c5
								
							
						
					
					
						commit
						dcedfb11b9
					
				
					 1 changed files with 18 additions and 6 deletions
				
			
		|  | @ -9,6 +9,9 @@ | ||||||
| import sys | import sys | ||||||
| import urllib.error | import urllib.error | ||||||
| import urllib.request | import urllib.request | ||||||
|  | import sys | ||||||
|  | 
 | ||||||
|  | TIMEOUT = 60  # seconds | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def _retry_thrice(func, exc, *args, **kwargs): | def _retry_thrice(func, exc, *args, **kwargs): | ||||||
|  | @ -166,20 +169,29 @@ def _test_urls(self, urls, handlers, retry=True): | ||||||
|                 req = expected_err = None |                 req = expected_err = None | ||||||
|             debug(url) |             debug(url) | ||||||
|             try: |             try: | ||||||
|                 f = urlopen(url, req) |                 f = urlopen(url, req, TIMEOUT) | ||||||
|             except EnvironmentError as err: |             except EnvironmentError as err: | ||||||
|                 debug(err) |                 debug(err) | ||||||
|                 if expected_err: |                 if expected_err: | ||||||
|                     msg = ("Didn't get expected error(s) %s for %s %s, got %s: %s" % |                     msg = ("Didn't get expected error(s) %s for %s %s, got %s: %s" % | ||||||
|                            (expected_err, url, req, type(err), err)) |                            (expected_err, url, req, type(err), err)) | ||||||
|                     self.assertTrue(isinstance(err, expected_err), msg) |                     self.assertTrue(isinstance(err, expected_err), msg) | ||||||
|  |             except urllib.error.URLError as err: | ||||||
|  |                 if isinstance(err[0], socket.timeout): | ||||||
|  |                     print("<timeout: %s>" % url, file=sys.stderr) | ||||||
|  |                     continue | ||||||
|  |                 else: | ||||||
|  |                     raise | ||||||
|             else: |             else: | ||||||
|                 with support.time_out, \ |                 try: | ||||||
|                      support.socket_peer_reset, \ |                     with support.time_out, \ | ||||||
|                      support.ioerror_peer_reset: |                          support.socket_peer_reset, \ | ||||||
|                     buf = f.read() |                          support.ioerror_peer_reset: | ||||||
|  |                         buf = f.read() | ||||||
|  |                         debug("read %d bytes" % len(buf)) | ||||||
|  |                 except socket.timeout: | ||||||
|  |                     print("<timeout: %s>" % url, file=sys.stderr) | ||||||
|                 f.close() |                 f.close() | ||||||
|                 debug("read %d bytes" % len(buf)) |  | ||||||
|             debug("******** next url coming up...") |             debug("******** next url coming up...") | ||||||
|             time.sleep(0.1) |             time.sleep(0.1) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Senthil Kumaran
						Senthil Kumaran