Mozprocess is a process-handling module developed by Mozilla, providing enhanced features beyond Python's standard `subprocess` module, such as improved child process handling (especially on Windows), flexible timeouts, and custom output handlers. While currently at version 1.4.0, the project's documentation notes it is poorly maintained and advises using Python's `subprocess` for routine needs. The project does not have a strict release cadence and updates are infrequent.
pip install mozprocessVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates launching a process using `mozprocess.ProcessHandler`, setting up a callback for each line of output, and defining a handler for process timeouts. It runs a simple Python script, capturing its output line by line and reporting its final status.
Prefer `subprocess` for general-purpose process management. Only use `mozprocess` for its specific features like advanced child process tracking, output line handlers, or specific timeout behaviors if strictly necessary for Mozilla-related tools. For simpler needs with timeouts/output handling, `mozprocess.run_and_wait()` is the recommended `mozprocess` interface.
Always check `p.timedOut` after `p.wait()` and explicitly `p.kill()` the process if it timed out and is no longer needed. Ensure `kill_on_timeout` is set correctly for `run()` if you expect automatic killing.
If custom `processOutputLine` handlers are used and you still want output to go to `sys.stdout` (or `sys.stderr`), explicitly pass `stream=sys.stdout` (or `stream=sys.stderr`) to the `ProcessHandler` constructor.
After `p.wait(timeout=X)`, check `if p.poll() is None:` or `if p.timedOut:`, and if the process is still active and undesirable, explicitly call `p.kill()` to terminate it.
If you wish to retain default console output *in addition* to your custom handlers, ensure that `stream=sys.stdout` is explicitly passed to the `ProcessHandler` constructor. Your custom handler can also explicitly print to `sys.stdout` or `sys.stderr`.
For most use cases requiring output capture or streaming, use `ProcessHandler`. If you must use `ProcessHandlerMixin`, you need to implement your own output capturing logic via `processOutputLine` handlers and manage streams explicitly.
No dependency data recorded yet.