示例#1
0
    def _execute_child(self, args, executable, preexec_fn, close_fds,
                       cwd, env, universal_newlines,
                       startupinfo, creationflags, shell,
                       p2cread, p2cwrite,
                       c2pread, c2pwrite,
                       errread, errwrite):

        try:
            pid, stdin, stdout, stderr =  \
                createProcess(args, close_fds, p2cread, p2cwrite,
                              c2pread, c2pwrite, errread, errwrite,
                              cwd, env, self._deathSignal)

            self.pid = pid
            self._closed = False
            self._returncode = None
        except:
            os.close(p2cwrite)
            os.close(errread)
            os.close(c2pread)
            raise
        finally:
            os.close(p2cread)
            os.close(errwrite)
            os.close(c2pwrite)
示例#2
0
文件: __init__.py 项目: oVirt/cpopen
    def _execute_child_v275(
            self, args, executable, preexec_fn, close_fds,
            cwd, env, universal_newlines,
            startupinfo, creationflags, shell,
            p2cread, p2cwrite,
            c2pread, c2pwrite,
            errread, errwrite,
            restore_sigpipe=False,
            _to_close=None
    ):

        if env is not None and not isinstance(env, list):
            env = list(("=".join(item) for item in env.iteritems()))

        if _to_close is None:
            _to_close = self._fds_to_close(p2cread, p2cwrite,
                                           c2pread, c2pwrite,
                                           errread, errwrite)

        def close_fd(fd):
            _to_close.remove(fd)
            os.close(fd)

        try:
            pid, stdin, stdout, stderr = createProcess(
                args, close_fds,
                p2cread or -1, p2cwrite or -1,
                c2pread or -1, c2pwrite or -1,
                errread or -1, errwrite or -1,
                cwd, env,
                self._deathSignal,
                self._childUmask,
                restore_sigpipe
            )

            self.pid = pid
        except:
            # Keep the original exception and reraise it after all fds are
            # closed, ignoring error during close. This is needed only for
            # Python 2.6, as Python 2.7 already does this when _execute_child
            # raises.
            t, v, tb = sys.exc_info()
            for fd in list(_to_close):
                try:
                    close_fd(fd)
                except OSError:
                    pass
            raise t, v, tb

        # If child was started, close the unused fds on the parent side. Note
        # that we don't want to hide exceptions here.
        for fd in (p2cread, c2pwrite, errwrite):
            if fd in _to_close:
                close_fd(fd)
示例#3
0
文件: __init__.py 项目: nirs/cpopen
    def _execute_child_v275(
            self, args, executable, preexec_fn, close_fds,
            cwd, env, universal_newlines,
            startupinfo, creationflags, shell,
            p2cread, p2cwrite,
            c2pread, c2pwrite,
            errread, errwrite,
    ):

        try:
            pid, stdin, stdout, stderr = createProcess(
                args, close_fds,
                p2cread or -1, p2cwrite or -1,
                c2pread or -1, c2pwrite or -1,
                errread or -1, errwrite or -1,
                cwd, env,
                self._deathSignal,
                self._childUmask,
            )

            self.pid = pid
        except:
            # Keep the original exception and reraise it after all fds are
            # closed, ignoring error during close. This is needed only for
            # Python 2.6, as Python 2.7 already does this when _execute_child
            # raises.
            t, v, tb = sys.exc_info()
            for fd in (
                p2cread, p2cwrite,
                c2pread, c2pwrite,
                errread, errwrite,
            ):
                try:
                    if fd:
                        os.close(fd)
                except OSError:
                    pass
            raise t, v, tb

        # If child was started, close the unused fds on the parent side. Note
        # that we don't want to hide exceptions here.
        for fd in (
            p2cread,
            errwrite,
            c2pwrite
        ):
            if fd:
                os.close(fd)
示例#4
0
    def _execute_child_v275(
        self,
        args,
        executable,
        preexec_fn,
        close_fds,
        cwd,
        env,
        universal_newlines,
        startupinfo,
        creationflags,
        shell,
        p2cread,
        p2cwrite,
        c2pread,
        c2pwrite,
        errread,
        errwrite,
    ):

        try:
            pid, stdin, stdout, stderr = createProcess(
                args,
                close_fds,
                p2cread or -1,
                p2cwrite or -1,
                c2pread or -1,
                c2pwrite or -1,
                errread or -1,
                errwrite or -1,
                cwd,
                env,
                self._deathSignal,
                self._childUmask,
            )

            self.pid = pid
        except:
            # Keep the original exception and reraise it after all fds are
            # closed, ignoring error during close. This is needed only for
            # Python 2.6, as Python 2.7 already does this when _execute_child
            # raises.
            t, v, tb = sys.exc_info()
            for fd in (
                    p2cread,
                    p2cwrite,
                    c2pread,
                    c2pwrite,
                    errread,
                    errwrite,
            ):
                try:
                    if fd:
                        os.close(fd)
                except OSError:
                    pass
            raise t, v, tb

        # If child was started, close the unused fds on the parent side. Note
        # that we don't want to hide exceptions here.
        for fd in (p2cread, errwrite, c2pwrite):
            if fd:
                os.close(fd)