From 9fae6ee6af42b7aca361deb478a212f573a0cd60 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Tue, 8 May 2012 14:31:52 +0000 Subject: [PATCH] Lit: rewind WinWaitReleased() stuff in TestRunner. r145222 "lit/TestRunner.py: [Win32] Introduce WinWaitReleased(f), to wait for file handles to be released by children." r145223 "lit/TestRunner.py: Use RemoveForce()." r145381 "lit/TestRunner.py: Try to catch ERROR_FILE_NOT_FOUND, too." r152916 "lit/TestRunner.py: [Win32] Check all opened_files[] released, rather than (obsoleted) written_files[]." r153172 "lit/TestRunner.py: [Win32] Rework WinWaitReleased() again! "win32file" from Python Win32 Extensions." git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156381 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/lit/lit/TestRunner.py | 66 ++++--------------------------------- 1 file changed, 6 insertions(+), 60 deletions(-) diff --git a/utils/lit/lit/TestRunner.py b/utils/lit/lit/TestRunner.py index b5f7986bfe7..3004d2c7134 100644 --- a/utils/lit/lit/TestRunner.py +++ b/utils/lit/lit/TestRunner.py @@ -23,56 +23,6 @@ kUseCloseFDs = not kIsWindows # Use temporary files to replace /dev/null on Windows. kAvoidDevNull = kIsWindows -# Negate if win32file is not found. -kHaveWin32File = kIsWindows - -def RemoveForce(f): - try: - os.remove(f) - except OSError: - pass - -def WinWaitReleased(f): - global kHaveWin32File - if not kHaveWin32File: - return - try: - import time - import win32file, pywintypes - retry_cnt = 256 - while True: - try: - h = win32file.CreateFile( - f, - win32file.GENERIC_READ, - 0, # Exclusive - None, - win32file.OPEN_EXISTING, - win32file.FILE_ATTRIBUTE_NORMAL, - None) - h.close() - return - except WindowsError, (winerror, strerror): - retry_cnt = retry_cnt - 1 - if retry_cnt <= 0: - raise - elif winerror == 32: # ERROR_SHARING_VIOLATION - pass - else: - raise - except pywintypes.error, e: - retry_cnt = retry_cnt - 1 - if retry_cnt <= 0: - raise - elif e[0]== 32: # ERROR_SHARING_VIOLATION - pass - else: - raise - time.sleep(0.01) - except ImportError, e: - kHaveWin32File = False - return - def executeCommand(command, cwd=None, env=None): p = subprocess.Popen(command, cwd=cwd, stdin=subprocess.PIPE, @@ -165,7 +115,6 @@ def executeShCmd(cmd, cfg, cwd, results): else: if r[2] is None: if kAvoidDevNull and r[0] == '/dev/null': - r[0] = None r[2] = tempfile.TemporaryFile(mode=r[1]) else: r[2] = open(r[0], r[1]) @@ -174,7 +123,7 @@ def executeShCmd(cmd, cfg, cwd, results): # FIXME: Actually, this is probably an instance of PR6753. if r[1] == 'a': r[2].seek(0, 2) - opened_files.append(r) + opened_files.append(r[2]) result = r[2] final_redirects.append(result) @@ -236,7 +185,7 @@ def executeShCmd(cmd, cfg, cwd, results): # on Win32, for example). Since we have already spawned the subprocess, our # handles have already been transferred so we do not need them anymore. for f in opened_files: - f[2].close() + f.close() # FIXME: There is probably still deadlock potential here. Yawn. procData = [None] * len(procs) @@ -275,15 +224,12 @@ def executeShCmd(cmd, cfg, cwd, results): else: exitCode = res - # Make sure opened_files is released by other (child) processes. - if kIsWindows: - for f in opened_files: - if f[0] is not None: - WinWaitReleased(f[0]) - # Remove any named temporary files we created. for f in named_temp_files: - RemoveForce(f) + try: + os.remove(f) + except OSError: + pass if cmd.negate: exitCode = not exitCode -- 2.34.1