119119    "run_with_locale" , "swap_item" ,
120120    "swap_attr" , "Matcher" , "set_memlimit" , "SuppressCrashReport" , "sortdict" ,
121121    "run_with_tz" , "PGO" , "missing_compiler_executable" , "fd_count" ,
122-     "ALWAYS_EQ" , "NEVER_EQ" , "LARGEST" , "SMALLEST" 
122+     "ALWAYS_EQ" , "NEVER_EQ" , "LARGEST" , "SMALLEST" ,
123+     "LOOPBACK_TIMEOUT" , "INTERNET_TIMEOUT" , "SHORT_TIMEOUT" , "LONG_TIMEOUT" ,
123124    ]
124125
126+ 
127+ # Timeout in seconds for tests using a network server listening on the network 
128+ # local loopback interface like 127.0.0.1. 
129+ # 
130+ # The timeout is long enough to prevent test failure: it takes into account 
131+ # that the client and the server can run in different threads or even different 
132+ # processes. 
133+ # 
134+ # The timeout should be long enough for connect(), recv() and send() methods 
135+ # of socket.socket. 
136+ LOOPBACK_TIMEOUT  =  5.0 
137+ if  sys .platform  ==  'win32'  and  platform .machine () ==  'ARM' :
138+     # bpo-37553: test_socket.SendfileUsingSendTest is taking longer than 2 
139+     # seconds on Windows ARM32 buildbot 
140+     LOOPBACK_TIMEOUT  =  10 
141+ 
142+ # Timeout in seconds for network requests going to the Internet. The timeout is 
143+ # short enough to prevent a test to wait for too long if the Internet request 
144+ # is blocked for whatever reason. 
145+ # 
146+ # Usually, a timeout using INTERNET_TIMEOUT should not mark a test as failed, 
147+ # but skip the test instead: see transient_internet(). 
148+ INTERNET_TIMEOUT  =  60.0 
149+ 
150+ # Timeout in seconds to mark a test as failed if the test takes "too long". 
151+ # 
152+ # The timeout value depends on the regrtest --timeout command line option. 
153+ # 
154+ # If a test using SHORT_TIMEOUT starts to fail randomly on slow buildbots, use 
155+ # LONG_TIMEOUT instead. 
156+ SHORT_TIMEOUT  =  30.0 
157+ 
158+ # Timeout in seconds to detect when a test hangs. 
159+ # 
160+ # It is long enough to reduce the risk of test failure on the slowest Python 
161+ # buildbots. It should not be used to mark a test as failed if the test takes 
162+ # "too long". The timeout value depends on the regrtest --timeout command line 
163+ # option. 
164+ LONG_TIMEOUT  =  5  *  60.0 
165+ 
166+ _NOT_SET  =  object ()
167+ 
168+ 
125169class  Error (Exception ):
126170    """Base class for regression test exceptions.""" 
127171
@@ -1231,7 +1275,7 @@ def check_valid_file(fn):
12311275    opener  =  urllib .request .build_opener ()
12321276    if  gzip :
12331277        opener .addheaders .append (('Accept-Encoding' , 'gzip' ))
1234-     f  =  opener .open (url , timeout = 15 )
1278+     f  =  opener .open (url , timeout = INTERNET_TIMEOUT )
12351279    if  gzip  and  f .headers .get ('Content-Encoding' ) ==  'gzip' :
12361280        f  =  gzip .GzipFile (fileobj = f )
12371281    try :
@@ -1542,9 +1586,12 @@ def get_socket_conn_refused_errs():
15421586
15431587
15441588@contextlib .contextmanager  
1545- def  transient_internet (resource_name , * , timeout = 30.0 , errnos = ()):
1589+ def  transient_internet (resource_name , * , timeout = _NOT_SET , errnos = ()):
15461590    """Return a context manager that raises ResourceDenied when various issues 
15471591    with the Internet connection manifest themselves as exceptions.""" 
1592+     if  timeout  is  _NOT_SET :
1593+         timeout  =  INTERNET_TIMEOUT 
1594+ 
15481595    default_errnos  =  [
15491596        ('ECONNREFUSED' , 111 ),
15501597        ('ECONNRESET' , 104 ),
@@ -2264,7 +2311,7 @@ def decorator(*args):
22642311
22652312
22662313@contextlib .contextmanager  
2267- def  wait_threads_exit (timeout = 60.0 ):
2314+ def  wait_threads_exit (timeout = None ):
22682315    """ 
22692316    bpo-31234: Context manager to wait until all threads created in the with 
22702317    statement exit. 
@@ -2278,6 +2325,8 @@ def wait_threads_exit(timeout=60.0):
22782325    which doesn't allow to wait for thread exit, whereas thread.Thread has a 
22792326    join() method. 
22802327    """ 
2328+     if  timeout  is  None :
2329+         timeout  =  SHORT_TIMEOUT 
22812330    old_count  =  _thread ._count ()
22822331    try :
22832332        yield 
@@ -2298,10 +2347,12 @@ def wait_threads_exit(timeout=60.0):
22982347            gc_collect ()
22992348
23002349
2301- def  join_thread (thread , timeout = 30.0 ):
2350+ def  join_thread (thread , timeout = None ):
23022351    """Join a thread. Raise an AssertionError if the thread is still alive 
23032352    after timeout seconds. 
23042353    """ 
2354+     if  timeout  is  None :
2355+         timeout  =  SHORT_TIMEOUT 
23052356    thread .join (timeout )
23062357    if  thread .is_alive ():
23072358        msg  =  f"failed to join the thread in { timeout :.1f}  
0 commit comments