carputils
Doxygen code documentation for the python framework controlling openCARP
Classes | Functions
carputils.divertoutput Namespace Reference

Classes

class  DivertOutputError
 

Functions

def intercept_OSError (func)
 Decorator to intercept file not found OSErrors. More...
 
def call (cmd, interactive=False, timeout=None, detached=False, stdout=None, stderr=None, args, kwargs)
 Run the specified command. More...
 
def subprocess_exceptions ()
 Make :func:call raise an exception on process non-zero exit status. More...
 
def process_timeout (process, timeout)
 
def mp_one_run (run)
 Define how to start a single run with multiprocessing. More...
 

Function Documentation

◆ call()

def carputils.divertoutput.call (   cmd,
  interactive = False,
  timeout = None,
  detached = False,
  stdout = None,
  stderr = None,
  args,
  kwargs 
)

Run the specified command.

This function manually captures the output and writes it to sys.stdout, meaning that replacing sys.stdout with a StringIO stream can be used to handle combined subprocess and python output more easily.

Example usage::

from carputils import divertoutput
divertoutput.call(['ls', '-ltr', 'mydir/'])

When used with the :func:subprocess_exceptions context manager, checks the return code of the finished process and raises an exception if it did not exit correctly.

See also the :func:carputils.stream.divert_std context manager, which allows control of the destination of the process output streams.

Parameters
cmdlist of str List of command line arguments to execute.

◆ intercept_OSError()

def carputils.divertoutput.intercept_OSError (   func)

Decorator to intercept file not found OSErrors.

◆ mp_one_run()

def carputils.divertoutput.mp_one_run (   run)

Define how to start a single run with multiprocessing.

run = (num, total, cmd) where

Parameters
numrun#; total: total number of runs; cmd: command line to run

◆ process_timeout()

def carputils.divertoutput.process_timeout (   process,
  timeout 
)

◆ subprocess_exceptions()

def carputils.divertoutput.subprocess_exceptions ( )

Make :func:call raise an exception on process non-zero exit status.

Example usage:

>>> from carputils import divertoutput
>>> with divertoutput.subprocess_exceptions():
>>> diveroutput.call(['ls', '-e'])
Traceback (most recent call last):
...
CalledProcessError: Command '['ls', '-e']' returned non-zero exit status 2