~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

  • Committer: Jelmer Vernooij
  • Date: 2011-08-04 13:30:30 UTC
  • mfrom: (6050 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6052.
  • Revision ID: jelmer@samba.org-20110804133030-uwo00unp8b0n782c
merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
576
576
        return argv
577
577
else:
578
578
    get_unicode_argv = None
 
579
 
 
580
 
 
581
if has_win32api:
 
582
    def _pywin32_is_local_pid_dead(pid):
 
583
        """True if pid doesn't correspond to live process on this machine"""
 
584
        try:
 
585
            handle = win32api.OpenProcess(1, False, pid) # PROCESS_TERMINATE
 
586
        except pywintypes.error, e:
 
587
            if e[0] == 5: # ERROR_ACCESS_DENIED
 
588
                # Probably something alive we're not allowed to kill
 
589
                return False
 
590
            elif e[0] == 87: # ERROR_INVALID_PARAMETER
 
591
                return True
 
592
            raise
 
593
        handle.close()
 
594
        return False
 
595
    is_local_pid_dead = _pywin32_is_local_pid_dead
 
596
elif has_ctypes and sys.platform == 'win32':
 
597
    from ctypes.wintypes import BOOL, DWORD, HANDLE
 
598
    _kernel32 = ctypes.windll.kernel32
 
599
    _CloseHandle = ctypes.WINFUNCTYPE(BOOL, HANDLE)(
 
600
        ("CloseHandle", _kernel32))
 
601
    _OpenProcess = ctypes.WINFUNCTYPE(HANDLE, DWORD, BOOL, DWORD)(
 
602
        ("OpenProcess", _kernel32))
 
603
    def _ctypes_is_local_pid_dead(pid):
 
604
        """True if pid doesn't correspond to live process on this machine"""
 
605
        handle = _OpenProcess(1, False, pid) # PROCESS_TERMINATE
 
606
        if not handle:
 
607
            errorcode = ctypes.GetLastError()
 
608
            if errorcode == 5: # ERROR_ACCESS_DENIED
 
609
                # Probably something alive we're not allowed to kill
 
610
                return False
 
611
            elif errorcode == 87: # ERROR_INVALID_PARAMETER
 
612
                return True
 
613
            raise ctypes.WinError(errorcode)
 
614
        _CloseHandle(handle)
 
615
        return False
 
616
    is_local_pid_dead = _ctypes_is_local_pid_dead