DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (5b81998bb7ab)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
provides python process management via an operating system
and platform transparent interface to Mozilla platforms of interest.
Mozprocess aims to provide the ability
to robustly terminate a process (by timeout or otherwise), along with
any child processes, on Windows, OS X, and Linux. Mozprocess utilizes
and extends `subprocess.Popen` to these ends.


is the central exposed API for mozprocess.  `ProcessHandler` utilizes
a contained subclass of [subprocess.Popen](http://docs.python.org/library/subprocess.html),
`Process`, which does the brunt of the process management.

Basic usage:

    process = ProcessHandler(['command', '-line', 'arguments'],
                             cwd=None, # working directory for cmd; defaults to None
                             env={},   # environment to use for the process; defaults to os.environ
    exit_code = process.waitForFinish(timeout=60) # seconds

`ProcessHandler` offers several other properties and methods as part of its API:

    def timedOut(self):
        """True if the process has timed out."""

    def run(self):
        Starts the process. waitForFinish must be called to allow the
        process to complete.

    def kill(self):
        Kills the managed process and if you created the process with
        'ignore_children=False' (the default) then it will also
        also kill all child processes spawned by it.
        If you specified 'ignore_children=True' when creating the process,
        only the root process will be killed.

        Note that this does not manage any state, save any output etc,
        it immediately kills the process.

    def readWithTimeout(self, f, timeout):
        Try to read a line of output from the file object |f|.
        |f| must be a pipe, like the |stdout| member of a subprocess.Popen
        object created with stdout=PIPE. If no output
        is received within |timeout| seconds, return a blank line.
        Returns a tuple (line, did_timeout), where |did_timeout| is True
        if the read timed out, and False otherwise.

        Calls a private member because this is a different function based on
        the OS

    def processOutputLine(self, line):
        """Called for each line of output that a process sends to stdout/stderr."""
        for handler in self.processOutputLineHandlers:

    def onTimeout(self):
        """Called when a process times out."""
        for handler in self.onTimeoutHandlers:

    def onFinish(self):
        """Called when a process finishes without a timeout."""
        for handler in self.onFinishHandlers:

    def waitForFinish(self, timeout=None, outputTimeout=None):
        Handle process output until the process terminates or times out.

        If timeout is not None, the process will be allowed to continue for
        that number of seconds before being killed.

        If outputTimeout is not None, the process will be allowed to continue
        for that number of seconds without producing any output before
        being killed.

See https://github.com/mozilla/mozbase/blob/master/mozprocess/mozprocess/processhandler.py
for the python implementation.

`ProcessHandler` extends `ProcessHandlerMixin` which by default prints the
output, logs to a file (if specified), and stores the output (if specified, by
default `True`).  `ProcessHandlerMixin`, by default, does none of these things
and has no handlers for `onTimeout`, `processOutput`, or `onFinish`.

`ProcessHandler` may be subclassed to handle process timeouts (by overriding
the `onTimeout()` method), process completion (by overriding
`onFinish()`), and to process the command output (by overriding


- Document improvements over `subprocess.Popen.kill`
- Introduce test the show improvements over `subprocess.Popen.kill`