Registry / devops / mozprocess

mozprocess

JSON →
library1.4.0pypypi✓ verified 85d ago

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 mozprocess
INSTALL
IMPORT
SIG · MOZPROCESS
M
mozprocess
devopspythonv1.4.0
Install
1.7s avg
Import
32ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.033s · 18.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.7s · import 0.031s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ProcessHandler
from mozprocess import ProcessHandler
ProcessHandlerMixin
from mozprocess import ProcessHandlerMixin
run_and_wait
from mozprocess import run_and_wait

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.

import sys import os from mozprocess import ProcessHandler def print_output_line(line): print(f"Process Output: {line.strip()}") def on_timeout_handler(): print("Process timed out!") # Example: Run a simple command and capture output command = ['python', '-c', 'import time; print("Hello"); time.sleep(1); print("World");'] try: # Using ProcessHandler to manage the process, capture output, and handle timeouts p = ProcessHandler( command, processOutputLine=[print_output_line], onTimeout=[on_timeout_handler], # Set a short timeout to demonstrate the onTimeout handler # For actual use, adjust or remove this timeout. timeout=5, outputTimeout=2 # Kill if no output for 2 seconds ) print(f"Executing command: {p.commandline}") p.run() return_code = p.wait() print(f"Process finished with return code: {return_code}") if p.timedOut: print("Note: Process was killed due to timeout.") except Exception as e: print(f"An error occurred: {e}")
Debug
Known issues
deprecatedMozilla documentation explicitly states 'THIS MODULE IS POORLY MAINTAINED' and recommends using Python's `subprocess` module for routine process handling. Mozprocess's features were designed for Python 2 limitations, many of which are no longer relevant in modern Python 3.
fix
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.
affects: All versions, especially when used in modern Python 3 environments.
gotchaThe `run()` method's `timeout` argument kills the process if the timeout is reached. However, the `wait()` method's `timeout` argument merely causes `wait()` to return after the specified seconds but *does not kill the process*. Failing to explicitly kill the process if `wait()` returns due to a timeout can lead to hanging processes.
fix
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.
affects: All versions.
gotchaBy default, `ProcessHandler` captures output, sends it to `sys.stdout`, and stores it internally. `ProcessHandlerMixin` (the base class), however, does not. If you provide custom output handlers to `ProcessHandler`, they *replace* the default behavior unless `stream=sys.stdout` is explicitly passed.
fix
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.
affects: All versions.
Errors
Common errors & fixes
Process hangs indefinitely, never returns, or consumes excessive resources after a `wait(timeout=...)` call.
The `wait()` method's `timeout` parameter only controls how long `wait()` itself will block, not the lifespan of the underlying process. If `wait()` returns `None` (indicating a timeout) or a return code that implies the process is still running, `mozprocess` will not automatically kill it.
fix
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.
Output is not printed to console when custom `processOutputLine` handlers are provided.
When you provide a list of callables to the `processOutputLine` argument in `ProcessHandler`, these handlers completely replace the default behavior of printing to `sys.stdout`.
fix
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`.
`AttributeError: 'ProcessHandlerMixin' object has no attribute 'output'` or `AttributeError: 'ProcessHandlerMixin' object has no attribute 'stream'`
`ProcessHandlerMixin` is a lower-level class that doesn't include the default output handling and storage mechanisms found in `ProcessHandler`. It's designed for more explicit, manual management.
fix
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.
Upgrade
Version history
1.4.0latest on PyPI · released Aug 19, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
mozprocess — pip install mozprocess · libregistry