コード例 #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):
                if not isinstance(args, types.StringTypes):
                    args = subprocess.list2cmdline(args)

                if startupinfo is None:
                    startupinfo = winprocess.STARTUPINFO()

                if None not in (p2cread, c2pwrite, errwrite):
                    startupinfo.dwFlags |= winprocess.STARTF_USESTDHANDLES

                    startupinfo.hStdInput = int(p2cread)
                    startupinfo.hStdOutput = int(c2pwrite)
                    startupinfo.hStdError = int(errwrite)
                if shell:
                    startupinfo.dwFlags |= winprocess.STARTF_USESHOWWINDOW
                    startupinfo.wShowWindow = winprocess.SW_HIDE
                    comspec = os.environ.get("COMSPEC", "cmd.exe")
                    args = comspec + " /c " + args

                # We create a new job for this process, so that we can kill
                # the process and any sub-processes
                self._job = winprocess.CreateJobObject()

                creationflags |= winprocess.CREATE_SUSPENDED
                creationflags |= winprocess.CREATE_UNICODE_ENVIRONMENT

                hp, ht, pid, tid = winprocess.CreateProcess(
                    executable,
                    args,
                    None,
                    None,  # No special security
                    1,  # Must inherit handles!
                    creationflags,
                    winprocess.EnvironmentBlock(env),
                    cwd,
                    startupinfo)

                self._child_created = True
                self._handle = hp
                self._thread = ht
                self.pid = pid

                # XXX: A try/except to fix UAC-related problems under
                # Windows Vista, when reparenting jobs.
                try:
                    winprocess.AssignProcessToJobObject(self._job, hp)
                except WindowsError:
                    pass
                winprocess.ResumeThread(ht)

                if p2cread is not None:
                    p2cread.Close()
                if c2pwrite is not None:
                    c2pwrite.Close()
                if errwrite is not None:
                    errwrite.Close()
コード例 #2
0
        def _internal_execute_child(self, args, executable, preexec_fn,
                                    close_fds, cwd, env, universal_newlines,
                                    startupinfo, creationflags, shell,
                                    to_close, p2cread, p2cwrite, c2pread,
                                    c2pwrite, errread, errwrite):

            # DLADD kam 04Dec07 Add real, user and system timings
            self._starttime = time.time()
            self.rtime = 0.0
            self.utime = 0.0
            self.stime = 0.0

            if not isinstance(args, types.StringTypes):
                args = subprocess.list2cmdline(args)

            if startupinfo is None:
                startupinfo = winprocess.STARTUPINFO()

            if None not in (p2cread, c2pwrite, errwrite):
                startupinfo.dwFlags |= winprocess.STARTF_USESTDHANDLES

                startupinfo.hStdInput = int(p2cread)
                startupinfo.hStdOutput = int(c2pwrite)
                startupinfo.hStdError = int(errwrite)
            if shell:
                startupinfo.dwFlags |= winprocess.STARTF_USESHOWWINDOW
                startupinfo.wShowWindow = winprocess.SW_HIDE
                comspec = os.environ.get("COMSPEC", "cmd.exe")
                args = comspec + " /c " + args

            def _close_in_parent(fd):
                fd.Close()
                if fd in to_close:
                    to_close.remove(fd)

            # We create a new job for this process, so that we can kill
            # the process and any sub-processes
            self._job = winprocess.CreateJobObject()

            creationflags |= winprocess.CREATE_SUSPENDED
            creationflags |= winprocess.CREATE_UNICODE_ENVIRONMENT
            try:
                hp, ht, pid, tid = winprocess.CreateProcess(
                    executable,
                    args,
                    None,
                    None,  # No special security
                    int(not close_fds),
                    creationflags,
                    winprocess.EnvironmentBlock(env),
                    cwd,
                    startupinfo)
            except pywintypes.error, e:
                # Translate pywintypes.error to WindowsError, which is
                # a subclass of OSError.  FIXME: We should really
                # translate errno using _sys_errlist (or similar), but
                # how can this be done from Python?
                raise WindowsError(*e.args)
コード例 #3
0
        def _execute_child(self, args, executable, preexec_fn, close_fds, cwd,
                           env, universal_newlines, startupinfo, creationflags,
                           shell, p2cread, p2cwrite, c2pread, c2pwrite,
                           errread, errwrite):
            """Execute program (MS Windows version)"""

            if not isinstance(args, types.StringTypes):
                args = list2cmdline(args)

            # Process startup details
            if startupinfo is None:
                startupinfo = STARTUPINFO()
            if None not in (p2cread, c2pwrite, errwrite):
                startupinfo.dwFlags |= STARTF_USESTDHANDLES
                startupinfo.hStdInput = p2cread
                startupinfo.hStdOutput = c2pwrite
                startupinfo.hStdError = errwrite

            if shell:
                startupinfo.dwFlags |= STARTF_USESHOWWINDOW
                startupinfo.wShowWindow = SW_HIDE
                comspec = os.environ.get("COMSPEC", "cmd.exe")
                args = comspec + " /c " + args
                if (GetVersion() >= 0x80000000L
                        or os.path.basename(comspec).lower() == "command.com"):
                    # Win9x, or using command.com on NT. We need to
                    # use the w9xpopen intermediate program. For more
                    # information, see KB Q150956
                    # (http://web.archive.org/web/20011105084002/http://support.microsoft.com/support/kb/articles/Q150/9/56.asp)
                    w9xpopen = self._find_w9xpopen()
                    args = '"%s" %s' % (w9xpopen, args)
                    # Not passing CREATE_NEW_CONSOLE has been known to
                    # cause random failures on win9x.  Specifically a
                    # dialog: "Your program accessed mem currently in
                    # use at xxx" and a hopeful warning about the
                    # stability of your system.  Cost is Ctrl+C wont
                    # kill children.
                    creationflags |= CREATE_NEW_CONSOLE

                # We create a new job for this process, so that we can kill
                # the process and any sub-processes
                self._job = winprocess.CreateJobObject()
                creationflags |= winprocess.CREATE_SUSPENDED
                # Vista will launch Komodo in a job object itself, so we need
                # to specify that the created process is not part of the Komodo
                # job object, but instead specify that it will be using a
                # separate breakaway job object, bug 83001.
                creationflags |= winprocess.CREATE_BREAKAWAY_FROM_JOB
コード例 #4
0
        def _execute_child(self, args, executable, preexec_fn, close_fds, cwd,
                           env, universal_newlines, startupinfo, creationflags,
                           shell, p2cread, p2cwrite, c2pread, c2pwrite,
                           errread, errwrite):
            if not isinstance(args, types.StringTypes):
                args = subprocess.list2cmdline(args)

            # Always or in the create new process group
            creationflags |= winprocess.CREATE_NEW_PROCESS_GROUP

            if startupinfo is None:
                startupinfo = winprocess.STARTUPINFO()

            if None not in (p2cread, c2pwrite, errwrite):
                startupinfo.dwFlags |= winprocess.STARTF_USESTDHANDLES

                startupinfo.hStdInput = int(p2cread)
                startupinfo.hStdOutput = int(c2pwrite)
                startupinfo.hStdError = int(errwrite)
            if shell:
                startupinfo.dwFlags |= winprocess.STARTF_USESHOWWINDOW
                startupinfo.wShowWindow = winprocess.SW_HIDE
                comspec = os.environ.get("COMSPEC", "cmd.exe")
                args = comspec + " /c " + args

            # determine if we can create create a job
            canCreateJob = winprocess.CanCreateJobObject()

            # set process creation flags
            creationflags |= winprocess.CREATE_SUSPENDED
            creationflags |= winprocess.CREATE_UNICODE_ENVIRONMENT
            if canCreateJob:
                # Uncomment this line below to discover very useful things about your environment
                #print "++++ killableprocess: releng twistd patch not applied, we can create job objects"
                creationflags |= winprocess.CREATE_BREAKAWAY_FROM_JOB

            # create the process
            hp, ht, pid, tid = winprocess.CreateProcess(
                executable,
                args,
                None,
                None,  # No special security
                1,  # Must inherit handles!
                creationflags,
                winprocess.EnvironmentBlock(env),
                cwd,
                startupinfo)
            self._child_created = True
            self._handle = hp
            self._thread = ht
            self.pid = pid
            self.tid = tid

            if canCreateJob:
                # We create a new job for this process, so that we can kill
                # the process and any sub-processes
                self._job = winprocess.CreateJobObject()
                winprocess.AssignProcessToJobObject(self._job, int(hp))
            else:
                self._job = None

            winprocess.ResumeThread(int(ht))
            ht.Close()

            if p2cread is not None:
                p2cread.Close()
            if c2pwrite is not None:
                c2pwrite.Close()
            if errwrite is not None:
                errwrite.Close()
            time.sleep(.1)
コード例 #5
0
        def _execute_child(self, args, executable, preexec_fn, close_fds, cwd,
                           env, universal_newlines, startupinfo, creationflags,
                           shell, p2cread, p2cwrite, c2pread, c2pwrite,
                           errread, errwrite):
            """Execute program (MS Windows version)"""

            if not isinstance(args, str):
                args = list2cmdline(args)

            # Process startup details
            if startupinfo is None:
                startupinfo = STARTUPINFO()
            if None not in (p2cread, c2pwrite, errwrite):
                startupinfo.dwFlags |= STARTF_USESTDHANDLES
                startupinfo.hStdInput = p2cread
                startupinfo.hStdOutput = c2pwrite
                startupinfo.hStdError = errwrite

            if shell:
                startupinfo.dwFlags |= STARTF_USESHOWWINDOW
                startupinfo.wShowWindow = SW_HIDE
                comspec = os.environ.get("COMSPEC", "cmd.exe")
                args = comspec + " /c " + args
                if (GetVersion() >= 0x80000000
                        or os.path.basename(comspec).lower() == "command.com"):
                    # Win9x, or using command.com on NT. We need to
                    # use the w9xpopen intermediate program. For more
                    # information, see KB Q150956
                    # (http://web.archive.org/web/20011105084002/http://support.microsoft.com/support/kb/articles/Q150/9/56.asp)
                    w9xpopen = self._find_w9xpopen()
                    args = '"%s" %s' % (w9xpopen, args)
                    # Not passing CREATE_NEW_CONSOLE has been known to
                    # cause random failures on win9x.  Specifically a
                    # dialog: "Your program accessed mem currently in
                    # use at xxx" and a hopeful warning about the
                    # stability of your system.  Cost is Ctrl+C wont
                    # kill children.
                    creationflags |= CREATE_NEW_CONSOLE

                # We create a new job for this process, so that we can kill
                # the process and any sub-processes
                self._job = winprocess.CreateJobObject()
                creationflags |= winprocess.CREATE_SUSPENDED
                # Vista will launch Komodo in a job object itself, so we need
                # to specify that the created process is not part of the Komodo
                # job object, but instead specify that it will be using a
                # separate breakaway job object, bug 83001.
                creationflags |= winprocess.CREATE_BREAKAWAY_FROM_JOB

            # Start the process
            try:
                hp, ht, pid, tid = CreateProcess(
                    executable,
                    args,
                    # no special security
                    None,
                    None,
                    int(not close_fds),
                    creationflags,
                    env,
                    cwd,
                    startupinfo)
            except pywintypes.error as e:
                # Translate pywintypes.error to WindowsError, which is
                # a subclass of OSError.  FIXME: We should really
                # translate errno using _sys_errlist (or simliar), but
                # how can this be done from Python?
                raise WindowsError(*e.args)
            except WindowsError:
                log.error("process.py: can't execute %r (%s)", executable,
                          args)
                raise

            # Retain the process handle, but close the thread handle
            self._child_created = True
            self._handle = hp
            self.pid = pid
            if self._job:
                # Resume the thread.
                winprocess.AssignProcessToJobObject(self._job, int(hp))
                winprocess.ResumeThread(int(ht))
            ht.Close()

            # Child is launched. Close the parent's copy of those pipe
            # handles that only the child should have open.  You need
            # to make sure that no handles to the write end of the
            # output pipe are maintained in this process or else the
            # pipe will not close when the child process exits and the
            # ReadFile will hang.
            if p2cread is not None:
                p2cread.Close()
            if c2pwrite is not None:
                c2pwrite.Close()
            if errwrite is not None:
                errwrite.Close()
コード例 #6
0
ファイル: process.py プロジェクト: alin23/SublimeCodeIntel
                def _execute_child(self, args, executable, preexec_fn,
                                   close_fds, pass_fds, cwd, env, startupinfo,
                                   creationflags, shell, p2cread, p2cwrite,
                                   c2pread, c2pwrite, errread, errwrite,
                                   unused_restore_signals,
                                   unused_start_new_session):
                    """Execute program (MS Windows version)"""

                    assert not pass_fds, "pass_fds not supported on Windows."

                    if not isinstance(args, str):
                        args = list2cmdline(args)

                    # Process startup details
                    if startupinfo is None:
                        startupinfo = STARTUPINFO()
                    if -1 not in (p2cread, c2pwrite, errwrite):
                        startupinfo.dwFlags |= STARTF_USESTDHANDLES
                        startupinfo.hStdInput = p2cread
                        startupinfo.hStdOutput = c2pwrite
                        startupinfo.hStdError = errwrite

                    if shell:
                        startupinfo.dwFlags |= STARTF_USESHOWWINDOW
                        startupinfo.wShowWindow = SW_HIDE
                        comspec = os.environ.get("COMSPEC", "cmd.exe")
                        args = '{} /c "{}"'.format(comspec, args)

                        # We create a new job for this process, so that we can kill
                        # the process and any sub-processes
                        self._job = winprocess.CreateJobObject()
                        creationflags |= winprocess.CREATE_SUSPENDED
                        # Vista will launch Komodo in a job object itself, so we need
                        # to specify that the created process is not part of the Komodo
                        # job object, but instead specify that it will be using a
                        # separate breakaway job object, bug 83001.
                        creationflags |= winprocess.CREATE_BREAKAWAY_FROM_JOB

                    # Start the process
                    try:
                        hp, ht, pid, tid = CreateProcess(
                            executable,
                            args,
                            # no special security
                            None,
                            None,
                            int(not close_fds),
                            creationflags,
                            env,
                            os.fspath(cwd) if cwd is not None else None,
                            startupinfo)
                    except WindowsError:
                        log.error("process.py: can't execute %r (%s)",
                                  executable, args)
                        raise
                    finally:
                        # Child is launched. Close the parent's copy of those pipe
                        # handles that only the child should have open.  You need
                        # to make sure that no handles to the write end of the
                        # output pipe are maintained in this process or else the
                        # pipe will not close when the child process exits and the
                        # ReadFile will hang.
                        if p2cread != -1:
                            p2cread.Close()
                        if c2pwrite != -1:
                            c2pwrite.Close()
                        if errwrite != -1:
                            errwrite.Close()
                        if hasattr(self, '_devnull'):
                            os.close(self._devnull)
                        # Prevent a double close of these handles/fds from __init__
                        # on error.
                        self._closed_child_pipe_fds = True

                    # Retain the process handle, but close the thread handle
                    self._child_created = True
                    self._handle = Handle(hp)
                    self.pid = pid
                    if self._job:
                        # Resume the thread.
                        winprocess.AssignProcessToJobObject(self._job, int(hp))
                        winprocess.ResumeThread(int(ht))
                    CloseHandle(ht)
コード例 #7
0
        def _execute_child(self, *args_tuple):
            # The arguments to this internal Python function changed on
            # Windows in 2.7.6
            # - https://trac.openmicroscopy.org.uk/ome/ticket/12320
            # Upstream bug and fix:
            # - https://bugzilla.mozilla.org/show_bug.cgi?id=958609
            # - https://github.com/mozilla/addon-sdk/pull/1379
            if sys.hexversion < 0x02070600:  # prior to 2.7.6
                (args, executable, preexec_fn, close_fds, cwd, env,
                 universal_newlines, startupinfo, creationflags, shell,
                 p2cread, p2cwrite, c2pread, c2pwrite, errread,
                 errwrite) = args_tuple
                to_close = set()
            else:  # 2.7.6 and later
                (args, executable, preexec_fn, close_fds, cwd, env,
                 universal_newlines, startupinfo, creationflags, shell,
                 to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread,
                 errwrite) = args_tuple

            if not isinstance(args, types.StringTypes):
                args = subprocess.list2cmdline(args)

            if startupinfo is None:
                startupinfo = winprocess.STARTUPINFO()

            if None not in (p2cread, c2pwrite, errwrite):
                startupinfo.dwFlags |= winprocess.STARTF_USESTDHANDLES

                startupinfo.hStdInput = int(p2cread)
                startupinfo.hStdOutput = int(c2pwrite)
                startupinfo.hStdError = int(errwrite)
            if shell:
                startupinfo.dwFlags |= winprocess.STARTF_USESHOWWINDOW
                startupinfo.wShowWindow = winprocess.SW_HIDE
                comspec = os.environ.get("COMSPEC", "cmd.exe")
                args = comspec + " /c " + args

            # We create a new job for this process, so that we can kill
            # the process and any sub-processes
            self._job = winprocess.CreateJobObject()

            creationflags |= winprocess.CREATE_SUSPENDED
            creationflags |= winprocess.CREATE_UNICODE_ENVIRONMENT

            hp, ht, pid, tid = winprocess.CreateProcess(
                executable,
                args,
                None,
                None,  # No special security
                1,  # Must inherit handles!
                creationflags,
                winprocess.EnvironmentBlock(env),
                cwd,
                startupinfo)

            self._child_created = True
            self._handle = hp
            self._thread = ht
            self.pid = pid

            winprocess.AssignProcessToJobObject(self._job, hp)
            winprocess.ResumeThread(ht)

            if p2cread is not None:
                p2cread.Close()
            if c2pwrite is not None:
                c2pwrite.Close()
            if errwrite is not None:
                errwrite.Close()
コード例 #8
0
        def _execute_child(self, args, executable, preexec_fn, close_fds, cwd,
                           env, universal_newlines, startupinfo, creationflags,
                           shell, p2cread, p2cwrite, c2pread, c2pwrite,
                           errread, errwrite):
            if not isinstance(args, types.StringTypes):
                args = subprocess.list2cmdline(args)

            # Always or in the create new process group
            creationflags |= winprocess.CREATE_NEW_PROCESS_GROUP

            if startupinfo is None:
                startupinfo = winprocess.STARTUPINFO()

            if None not in (p2cread, c2pwrite, errwrite):
                startupinfo.dwFlags |= winprocess.STARTF_USESTDHANDLES

                startupinfo.hStdInput = int(p2cread)
                startupinfo.hStdOutput = int(c2pwrite)
                startupinfo.hStdError = int(errwrite)
            if shell:
                startupinfo.dwFlags |= winprocess.STARTF_USESHOWWINDOW
                startupinfo.wShowWindow = winprocess.SW_HIDE
                comspec = os.environ.get("COMSPEC", "cmd.exe")
                args = comspec + " /c " + args

            # determine if we can create create a job
            canCreateJob = winprocess.CanCreateJobObject()

            # set process creation flags
            creationflags |= winprocess.CREATE_SUSPENDED
            creationflags |= winprocess.CREATE_UNICODE_ENVIRONMENT
            if canCreateJob:
                # Uncomment this line below to discover very useful things about your environment
                #print "++++ killableprocess: releng twistd patch not applied, we can create job objects"
                creationflags |= winprocess.CREATE_BREAKAWAY_FROM_JOB

            # create the process
            hp, ht, pid, tid = winprocess.CreateProcess(
                executable,
                args,
                None,
                None,  # No special security
                1,  # Must inherit handles!
                creationflags,
                winprocess.EnvironmentBlock(env),
                cwd,
                startupinfo)
            self._child_created = True
            self._handle = hp
            self._thread = ht
            self.pid = pid
            self.tid = tid

            if canCreateJob:
                # We create a new job for this process, so that we can kill
                # the process and any sub-processes
                self._job = winprocess.CreateJobObject()
                # Allow subprocesses to break away from us - necessary for
                # flash with protected mode
                jbli = JOBOBJECT_BASIC_LIMIT_INFORMATION(
                    c_longlong(0),  # per process time limit (ignored)
                    c_longlong(0),  # per job user time limit (ignored)
                    winprocess.JOB_OBJECT_LIMIT_BREAKAWAY_OK,
                    0,  # min working set (ignored)
                    0,  # max working set (ignored)
                    0,  # active process limit (ignored)
                    None,  # affinity (ignored)
                    0,  # Priority class (ignored)
                    0,  # Scheduling class (ignored)
                )

                iocntr = IO_COUNTERS()
                jeli = JOBOBJECT_EXTENDED_LIMIT_INFORMATION(
                    jbli,  # basic limit info struct
                    iocntr,  # io_counters (ignored)
                    0,  # process mem limit (ignored)
                    0,  # job mem limit (ignored)
                    0,  # peak process limit (ignored)
                    0)  # peak job limit (ignored)

                winprocess.SetInformationJobObject(
                    self._job, JobObjectExtendedLimitInformation,
                    addressof(jeli), sizeof(jeli))
                winprocess.AssignProcessToJobObject(self._job, int(hp))
            else:
                self._job = None

            winprocess.ResumeThread(int(ht))
            ht.Close()

            if p2cread is not None:
                p2cread.Close()
            if c2pwrite is not None:
                c2pwrite.Close()
            if errwrite is not None:
                errwrite.Close()
            time.sleep(.1)
コード例 #9
0
        def _execute_child(self, args, executable, preexec_fn, close_fds, cwd,
                           env, universal_newlines, startupinfo, creationflags,
                           shell, p2cread, p2cwrite, c2pread, c2pwrite,
                           errread, errwrite):
            if not isinstance(args, types.StringTypes):
                args = subprocess.list2cmdline(args)

            if startupinfo is None:
                startupinfo = winprocess.STARTUPINFO()

            if None not in (p2cread, c2pwrite, errwrite):
                startupinfo.dwFlags |= winprocess.STARTF_USESTDHANDLES

                startupinfo.hStdInput = int(p2cread)
                startupinfo.hStdOutput = int(c2pwrite)
                startupinfo.hStdError = int(errwrite)
            if shell:
                startupinfo.dwFlags |= winprocess.STARTF_USESHOWWINDOW
                startupinfo.wShowWindow = winprocess.SW_HIDE
                comspec = os.environ.get("COMSPEC", "cmd.exe")
                args = comspec + " /c " + args

            # We create a new job for this process, so that we can kill
            # the process and any sub-processes
            self._job = winprocess.CreateJobObject()

            creationflags |= winprocess.CREATE_SUSPENDED
            creationflags |= winprocess.CREATE_UNICODE_ENVIRONMENT

            hp, ht, pid, tid = winprocess.CreateProcess(
                executable,
                args,
                None,
                None,  # No special security
                1,  # Must inherit handles!
                creationflags,
                winprocess.EnvironmentBlock(env),
                cwd,
                startupinfo)

            self._child_created = True
            self._handle = hp
            self._thread = ht
            self.pid = pid
            self.tid = tid

            winprocess.AssignProcessToJobObject(self._job, hp)
            winprocess.ResumeThread(ht)

            if p2cread is not None:
                p2cread.Close()
            if c2pwrite is not None:
                c2pwrite.Close()
            if errwrite is not None:
                errwrite.Close()
            time.sleep(.1)
            p = winprocess.QueryInformationJobObject(
                self._job, 8)['BasicInfo']['ActiveProcesses']
            if p is 0:
                self._job_working = False
            else:
                self._job_working = True