5050from datetime import datetime
5151from Queue import Queue , Empty
5252
53+ try :
54+ reduce # Python 2
55+ except NameError : # Python 3
56+ from functools import reduce
57+
58+ try :
59+ xrange # Python 2
60+ except NameError :
61+ xrange = range # Python 3
62+
5363logger = logging .getLogger ('testrunner' )
5464skip_regex = re .compile (r'# SKIP\S*\s+(.*)' , re .IGNORECASE )
5565
@@ -110,9 +120,9 @@ def Run(self, tasks):
110120 for thread in threads :
111121 # Use a timeout so that signals (ctrl-c) will be processed.
112122 thread .join (timeout = 10000000 )
113- except (KeyboardInterrupt , SystemExit ), e :
123+ except (KeyboardInterrupt , SystemExit ) as e :
114124 self .shutdown_event .set ()
115- except Exception , e :
125+ except Exception as e :
116126 # If there's an exception we schedule an interruption for any
117127 # remaining threads.
118128 self .shutdown_event .set ()
@@ -149,7 +159,7 @@ def RunSingle(self, parallel, thread_id):
149159 output = case .Run ()
150160 output .diagnostic .append ('ECONNREFUSED received, test retried' )
151161 case .duration = (datetime .now () - start )
152- except IOError , e :
162+ except IOError as e :
153163 return
154164 if self .shutdown_event .is_set ():
155165 return
@@ -600,7 +610,7 @@ def Win32SetErrorMode(mode):
600610 prev_error_mode = SEM_INVALID_VALUE
601611 try :
602612 import ctypes
603- prev_error_mode = ctypes .windll .kernel32 .SetErrorMode (mode );
613+ prev_error_mode = ctypes .windll .kernel32 .SetErrorMode (mode )
604614 except ImportError :
605615 pass
606616 return prev_error_mode
@@ -619,15 +629,15 @@ def KillTimedOutProcess(context, pid):
619629def RunProcess (context , timeout , args , ** rest ):
620630 if context .verbose : print ("#" , " " .join (args ))
621631 popen_args = args
622- prev_error_mode = SEM_INVALID_VALUE ;
632+ prev_error_mode = SEM_INVALID_VALUE
623633 if utils .IsWindows ():
624634 if context .suppress_dialogs :
625635 # Try to change the error mode to avoid dialogs on fatal errors. Don't
626636 # touch any existing error mode flags by merging the existing error mode.
627637 # See http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx.
628- error_mode = SEM_NOGPFAULTERRORBOX ;
629- prev_error_mode = Win32SetErrorMode (error_mode );
630- Win32SetErrorMode (error_mode | prev_error_mode );
638+ error_mode = SEM_NOGPFAULTERRORBOX
639+ prev_error_mode = Win32SetErrorMode (error_mode )
640+ Win32SetErrorMode (error_mode | prev_error_mode )
631641
632642 faketty = rest .pop ('faketty' , False )
633643 pty_out = rest .pop ('pty_out' )
@@ -696,7 +706,7 @@ def CheckedUnlink(name):
696706 while True :
697707 try :
698708 os .unlink (name )
699- except OSError , e :
709+ except OSError as e :
700710 # On Windows unlink() fails if another process (typically a virus scanner
701711 # or the indexing service) has the file open. Those processes keep a
702712 # file open for a short time only, so yield and try again; it'll succeed.
@@ -765,8 +775,8 @@ def disableCoreFiles():
765775 else :
766776 os .close (fd_out )
767777 os .close (fd_err )
768- output = file (outname ).read ()
769- errors = file (errname ).read ()
778+ output = open (outname ).read ()
779+ errors = open (errname ).read ()
770780 CheckedUnlink (outname )
771781 CheckedUnlink (errname )
772782
0 commit comments