code: def get_pid_from_tid(self, dwThreadId):
          
          try:
  
              # No good, because in XP and below it tries to get the PID
              # through the toolhelp API, and that's slow. We don't want
              # to scan for threads over and over for each call.
  ##            dwProcessId = Thread(dwThreadId).get_pid()
  
              # This API only exists in Windows 2003, Vista and above.
              try:
                  hThread = win32.OpenThread(
                      win32.THREAD_QUERY_LIMITED_INFORMATION, False, dwThreadId)
              except WindowsError:
                  e = sys.exc_info()[1]
                  if e.winerror != win32.ERROR_ACCESS_DENIED:
                      raise
                  hThread = win32.OpenThread(
                      win32.THREAD_QUERY_INFORMATION, False, dwThreadId)
              try:
                  return win32.GetProcessIdOfThread(hThread)
              finally:
                  hThread.close()
  
          # If all else fails, go through all processes in the snapshot
          # looking for the one that owns the thread we're looking for.
          # If the snapshot was empty the iteration should trigger an
          # automatic scan. Otherwise, it'll look for the thread in what
          # could possibly be an outdated snapshot.
          except Exception:
              for aProcess in self.iter_processes():
                  if aProcess.has_thread(dwThreadId):
                      return aProcess.get_pid()
  
          # The thread wasn't found, so let's refresh the snapshot and retry.
          # Normally this shouldn't happen since this function is only useful
          # for the debugger, so the thread should already exist in the snapshot.
          self.scan_processes_and_threads()
          for aProcess in self.iter_processes():
              if aProcess.has_thread(dwThreadId):
                  return aProcess.get_pid()
  
          # No luck! It appears to be the thread doesn't exist after all.
          msg = "Unknown thread ID %d" % dwThreadId
          raise KeyError(msg)
docs: Retrieves the global ID of the process that owns the thread.
  
          @type  dwThreadId: int
          @param dwThreadId: Thread global ID.
  
          @rtype:  int
          @return: Process global ID.
  
          @raise KeyError: The thread does not exist.