diff --git a/libcxx/utils/libcxx/util.py b/libcxx/utils/libcxx/util.py --- a/libcxx/utils/libcxx/util.py +++ b/libcxx/utils/libcxx/util.py @@ -102,7 +102,7 @@ (or the PATH environment variable, if unspecified).""" if paths is None: - paths = os.environ.get('PATH','') + paths = os.environ.get('PATH', '') # Check for absolute match first. if os.path.isfile(command): @@ -202,23 +202,21 @@ stderr=subprocess.PIPE, env=env, close_fds=kUseCloseFDs) timerObject = None - # FIXME: Because of the way nested function scopes work in Python 2.x we - # need to use a reference to a mutable object rather than a plain - # bool. In Python 3 we could use the "nonlocal" keyword but we need - # to support Python 2 as well. - hitTimeOut = [False] + + nonlocal hitTimeOut + hitTimeOut = False try: if timeout > 0: def killProcess(): # We may be invoking a shell so we need to kill the # process and all its children. - hitTimeOut[0] = True + hitTimeOut = True killProcessAndChildren(p.pid) timerObject = threading.Timer(timeout, killProcess) timerObject.start() - out,err = p.communicate(input=input) + out, err = p.communicate(input=input) exitCode = p.wait() finally: if timerObject != None: @@ -228,7 +226,7 @@ out = convert_string(out) err = convert_string(err) - if hitTimeOut[0]: + if hitTimeOut: raise ExecuteCommandTimeoutException( msg='Reached timeout of {} seconds'.format(timeout), out=out,