def _setupChild(self, fdmap):
        debug = self.debug_child
        if debug:
            errfd = sys.stderr
            errfd.write("starting _setupChild\n")

        destList = fdmap.values()
        for fd in _listOpenFDs():
            if fd in destList:
                continue
            if debug and fd == errfd.fileno():
                continue
            try:
                os.close(fd)
            except:
                pass

        # at this point, the only fds still open are the ones that need to
        # be moved to their appropriate positions in the child (the targets
        # of fdmap, i.e. fdmap.values() )

        if debug: print("fdmap", fdmap, file=errfd)
        for child in sorted(fdmap.keys()):
            target = fdmap[child]
            if target == child:
                # fd is already in place
                if debug: print("%d already in place" % target, file=errfd)
                fdesc._unsetCloseOnExec(child)
            else:
                if child in fdmap.values():
                    # we can't replace child-fd yet, as some other mapping
                    # still needs the fd it wants to target. We must preserve
                    # that old fd by duping it to a new home.
                    newtarget = os.dup(child) # give it a safe home
                    if debug: print("os.dup(%d) -> %d" % (child, newtarget),
                                    file=errfd)
                    os.close(child) # close the original
                    for c, p in items(fdmap):
                        if p == child:
                            fdmap[c] = newtarget # update all pointers
                # now it should be available
                if debug: print("os.dup2(%d,%d)" % (target, child), file=errfd)
                os.dup2(target, child)

        # At this point, the child has everything it needs. We want to close
        # everything that isn't going to be used by the child, i.e.
        # everything not in fdmap.keys(). The only remaining fds open are
        # those in fdmap.values().

        # Any given fd may appear in fdmap.values() multiple times, so we
        # need to remove duplicates first.

        old = []
        for fd in fdmap.values():
            if not fd in old:
                if not fd in fdmap.keys():
                    old.append(fd)
        if debug: print("old", old, file=errfd)
        for fd in old:
            os.close(fd)

        self._resetSignalDisposition()
Finds the first matching subelement, by tag name.
dataset/ETHPy150Open twisted/twisted/twisted/internet/process.py/Process._setupChild--crossover with--dataset/ETHPy150Open flosch/simpleapi/example_project/client/python/sapi/message.py/MessageElement.find