# HG changeset patch # User Lee Cantey # Date 1143771608 28800 # Node ID 6328445b0e71754c3ce6d89c7fb8c3773488c4a5 # Parent 3bdd3bf17cfa33859f5ab1ab5b4735de8c8dbec4 Fixes to testpid() for Windows. Handle processes that no longer exist and processes that belong to another user. Enables the lock breaking changes from d314a89fa4f1 and subsequently "fixes" the left over locks reported in bug 112. diff -r 3bdd3bf17cfa -r 6328445b0e71 mercurial/util.py --- a/mercurial/util.py Thu Mar 30 18:43:46 2006 +0200 +++ b/mercurial/util.py Thu Mar 30 18:20:08 2006 -0800 @@ -535,9 +535,10 @@ pf = pf[1:-1] # Remove the quotes return pf - try: # ActivePython can create hard links using win32file module - import win32api, win32con, win32file + try: # Mark Hammond's win32all package allows better functionality on Windows + import win32api, win32con, win32file, pywintypes + # create hard links using win32file module def os_link(src, dst): # NB will only succeed on NTFS win32file.CreateHardLink(dst, src) @@ -554,12 +555,19 @@ return os.stat(pathname).st_nlink def testpid(pid): - '''return False if pid is dead, True if running or not known''' + '''return True if pid is still running or unable to determine, False otherwise''' try: - win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION, - False, pid) - except: - return True + handle = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION, False, pid) + if handle: + status = win32process.GetExitCodeProcess(handle) + if status == win32con.STILL_ACTIVE: + return True + else: + return False + except pywintypes.error, details: + if details[0] == 87: # ERROR_INVALID_PARAMETER + return False + return True except ImportError: def testpid(pid):