def get_process_handle (pid, handle):
  try:
    hProcess = win32api.OpenProcess (win32con.PROCESS_DUP_HANDLE, 0, pid)
    return win32api.DuplicateHandle (hProcess, handle, CURRENT_PROCESS, 0, 0, win32con.DUPLICATE_SAME_ACCESS)
  except win32api.error, (errno, errctx, errmsg):
    if errno in (
      winerror.ERROR_ACCESS_DENIED,
      winerror.ERROR_INVALID_PARAMETER,
      winerror.ERROR_INVALID_HANDLE,
      winerror.ERROR_NOT_SUPPORTED
    ):
      return None
    else:
      raise
dataset/ETHPy150Open tjguk/winsys/random/file_handles.py/get_process_handle/original