mozilla

Revision 68179 of Mozprocess

  • Revision slug: Mozprocess
  • Revision title: Mozprocess
  • Revision id: 68179
  • Created:
  • Creator: jhammel
  • Is current revision? No
  • Comment 2 words added, 22 words removed

Revision Content

mozprocess 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.

API

mozprocess.processhandler:ProcessHandler is the central exposed API for mozprocess. ProcessHandler utilizes a contained subclass of subprocess.Popen, 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

See an example in https://github.com/mozilla/mozbase/b...profilepath.py

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 processOutputLine()).

TODO

  • Document improvements over subprocess.Popen.kill

Revision Source

<p><a class=" link-https" href="https://github.com/mozilla/mozbase/tree/master/mozprocess">mozprocess</a> 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 <code>subprocess.Popen</code> to these ends.</p> <h1 id="API">API</h1> <p><a class=" link-https" href="https://github.com/mozilla/mozbase/blob/master/mozprocess/mozprocess/processhandler.py">mozprocess.processhandler:ProcessHandler</a> is the central exposed API for mozprocess. <code>ProcessHandler</code> utilizes a contained subclass of <a class=" external" href="http://docs.python.org/library/subprocess.html">subprocess.Popen</a>, <code>Process</code>, which does the brunt of the process management.</p> <p>Basic usage:</p> <pre><code>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
</code></pre> <p>See an example in <a class=" link-https" href="https://github.com/mozilla/mozbase/blob/master/mutt/mutt/tests/python/testprofilepath.py" rel="freelink">https://github.com/mozilla/mozbase/b...profilepath.py</a></p> <p><code>ProcessHandler</code> may be subclassed to handle process timeouts (by overriding the <code>onTimeout()</code> method), process completion (by overriding <code>onFinish()</code>), and to process the command output (by overriding <code>processOutputLine()</code>).</p> <h1 id="TODO">TODO</h1> <ul> <li>Document improvements over <code>subprocess.Popen.kill</code></li> </ul>
Revert to this revision