Get the latest PID as pointed by the Head PID.

        If the 'pid' is a Head PID, return the latest of its children.
        If the 'pid' is a Version PID, return the latest of its siblings.
        Return None for the non-versioned PIDs.
163655
def last_child(self):
        
        return self.children.filter(
            PIDRelation.index.isnot(None)).ordered().first()
220793
def getLastModified(self):
        ""
        last_modified = self.headers.get('last-modified')
        if last_modified:
            last_modified = self.convertTimeString(last_modified)
        return last_modified
635860
def get_current_head(graph):
    
    session = new_session(graph)
    try:
        result = session.execute("SELECT version_num FROM alembic_version")
    except ProgrammingError:
        return None
    else:
        return result.scalar()
    finally:
        session.close()
895410
def next_sibling(self):
        
        stmts = self.parent.child_sequence(self)
        index = stmts.index(self)
        try:
            return stmts[index + 1]
        except IndexError:
            pass
472309
def pid(self):
        
        try:

            with open(self.pidfile, 'r') as pidfile:

                try:

                    pid = int(pidfile.read().strip())

                except ValueError:

                    return None

                try:

                    os.kill(pid, 0)

                except OSError as e:

                    if e.errno == errno.EPERM:

                        return pid

                    elif e.errno == errno.ESRCH:

                        return None

                    LOG.exception(
                        "os.kill returned unhandled error "
                        "{0}".format(e.strerror)
                    )
                    sys.exit(exit.PIDFILE_ERROR)

                return pid

        except IOError:

            if not os.path.isfile(self.pidfile):

                return None

            LOG.exception("Failed to read pidfile {0}.".format(self.pidfile))
            sys.exit(exit.PIDFILE_INACCESSIBLE)
469171
def check(self):
        
        current = self._get_current()
        highest = self._get_highest_version()
        return highest > current
1069990
def get_next(self):
        

        while self.stack:
            if self.stack[-1].wkids:
                node = self.stack[-1].wkids.pop(0)
                if not self.stack[-1].wkids:
                    self.stack[-1].wkids = None
                if node in self.history:
                    self.cycle_func(node, self.stack)
                else:
                    node.wkids = copy.copy(self.kids_func(node, self.stack[-1]))
                    self.stack.append(node)
                    self.history[node] = None
            else:
                node = self.stack.pop()
                del self.history[node]
                if node:
                    if self.stack:
                        parent = self.stack[-1]
                    else:
                        parent = None
                    self.eval_func(node, parent)
                return node
        return None
1182145
private int getPid() {

	PageContext pc = ThreadLocalPageContext.get();
	if (pc == null) {
	    pc = CFMLEngineFactory.getInstance().getThreadPageContext();
	    if (pc == null) throw new RuntimeException("cannot get pid for current thread");
	}
	return pc.getId();
    }
45225
def is_obsoleted_by_pid(pid):
    
    return d1_gmn.app.models.ScienceObject.objects.filter(
        obsoleted_by__did=pid
    ).exists()
179728
def last_update_time(self) -> float:
        """"""
        stdout = self.stdout_interceptor
        stderr = self.stderr_interceptor

        return max([
            self._last_update_time,
            stdout.last_write_time if stdout else 0,
            stderr.last_write_time if stderr else 0,
        ])
690462
def next(self):
        
        if self._order_by == 'oldest':
            return self.newer
        if self._order_by == 'newest':
            return self.older
        return None
1245199
def sibling(self, offs=1):
        '''
        
        '''
        indx = self.pindex + offs

        if indx < 0:
            return None

        if indx >= len(self.parent.kids):
            return None

        return self.parent.kids[indx]
89956
def fetch_new_id(self, ):
        
        parent = self.get_parent()
        if parent:
            others = parent._children
        else:
            others = [r for r in self.get_root()._reftracks if r.get_parent() is None]
        others = [r for r in others
                  if r != self
                  and r.get_typ() == self.get_typ()
                  and r.get_element() == self.get_element()]
        highest = -1
        for r in others:
            identifier = r.get_id()
            if identifier > highest:
                highest = identifier
        return highest + 1
1332313
def _get_shell_pid():
    """"""
    proc = Process(os.getpid())

    try:
        return proc.parent().pid
    except TypeError:
        return proc.parent.pid
1243486
public long getPID() {
		long currentPID = cachedPID.get();
		if (currentPID != 0) {
			return currentPID;
		}
		try {
			currentPID = detectPID();
		} catch (Throwable cause) {
			logger.info("Unable to detect process ID!", cause);
		}
		if (currentPID == 0) {
			currentPID = System.nanoTime();
			if (!cachedPID.compareAndSet(0, currentPID)) {
				currentPID = cachedPID.get();
			}
		} else {
			cachedPID.set(currentPID);
		}
		return currentPID;
	}
181116
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)
975070
def _get_siblings(self, pos):
        
        parent = self.parent_position(pos)
        siblings = [pos]
        if parent is not None:
            siblings = self._list_dir(parent)
        return siblings