subprocess2
index

  python-subprocess2
 
Copyright (c) 2015 Timothy Savannah LGPL All rights reserved. See LICENSE file for more details.
 
This module provides extensions to the standard "subprocess" module
Importing this module modifies the global subprocess module. You can use it like:
 
  from subprocess2 import Popen
 
or
 
  import subprocess2
 
  from subprocess import Popen

 
Package Contents
       
BackgroundTask

 
Classes
       
__builtin__.object
subprocess.Popen
exceptions.Exception(exceptions.BaseException)
subprocess.CalledProcessError

 
class CalledProcessError(exceptions.Exception)
    This exception is raised when a process run by check_call() or
check_output() returns a non-zero exit status.
The exit status will be stored in the returncode attribute;
check_output() will also store the output in the output attribute.
 
 
Method resolution order:
CalledProcessError
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, returncode, cmd, output=None)
__str__(self)

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class Popen(__builtin__.object)
     Methods defined here:
__del__(self, _maxint=9223372036854775807)
__init__(self, args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0)
Create new Popen instance.
communicate(self, input=None)
Interact with process: Send data to stdin.  Read data from
stdout and stderr, until end-of-file is reached.  Wait for
process to terminate.  The optional input argument should be a
string to be sent to the child process, or None, if no data
should be sent to the child.
 
communicate() returns a tuple (stdout, stderr).
kill(self)
Kill the process with SIGKILL
pipe_cloexec(self)
Create a pipe with FDs set CLOEXEC.
poll(self)
runInBackground(self, pollInterval=0.1, encoding=False)
runInBackground - Create a background thread which will manage this process, automatically read from streams, and perform any cleanups
 
  The object returned is a "BackgroundTaskInfo" object, and represents the state of the process. It is updated automatically as the program runs,
    and if stdout or stderr are streams, they are automatically read from and populated into this object.
 
 @see BackgroundTaskInfo for more info or https://htmlpreview.github.io/?https://raw.githubusercontent.com/kata198/python-subprocess2/master/doc/subprocess2.BackgroundTask.html
 
@param pollInterval - Amount of idle time between polling
@param encoding - Default False. If provided, data will be decoded using the value of this field as the codec name (e.x. "utf-8"). Otherwise, data will be stored as bytes.
send_signal(self, sig)
Send a signal to the process
terminate(self)
Terminate the process with SIGTERM
wait(self)
Wait for child process to terminate.  Returns returncode
attribute.
waitOrTerminate(self, timeoutSeconds, pollInterval=0.05, terminateToKillSeconds=1.5)
waitOrTerminate - Wait up to a certain number of seconds for the process to end.
 
    If the process is running after the timeout has been exceeded, a SIGTERM will be sent. 
    Optionally, an additional SIGKILL can be sent after some configurable interval. See #terminateToKillSeconds doc below
 
    @param timeoutSeconds <float> - Number of seconds to wait
 
    @param pollInterval <float> (default .05)- Number of seconds between each poll
 
    @param terminateToKillSeconds <float/None> (default 1.5) - If application does not end before #timeoutSeconds , terminate() will be called.
 
        * If this is set to None, an additional #pollInterval sleep will occur after calling .terminate, to allow the application to cleanup. returnCode will be return of app if finished, or None if did not complete.
        * If this is set to 0, no terminate signal will be sent, but directly to kill. Because the application cannot trap this, returnCode will be None.
        * If this is set to > 0, that number of seconds maximum will be given between .terminate and .kill. If the application does not terminate before KILL, returnCode will be None.
 
    Windows Note -- On windows SIGTERM and SIGKILL are the same thing.
 
    @return dict { 'returnCode' : <int or None> , 'actionTaken' : <int mask of SUBPROCESS2_PROCESS_*> }
        Returns a dict representing results: 
            "returnCode" matches return of application, or None per #terminateToKillSeconds doc above.
            "actionTaken" is a mask of the SUBPROCESS2_PROCESS_* variables. If app completed normally, it will be SUBPROCESS2_PROCESS_COMPLETED, otherwise some mask of SUBPROCESS2_PROCESS_TERMINATED and/or SUBPROCESS2_PROCESS_KILLED
waitUpTo(self, timeoutSeconds, pollInterval=0.05)
Popen.waitUpTo - Wait up to a certain number of seconds for the process to end.
 
    @param timeoutSeconds <float> - Number of seconds to wait
 
    @param pollInterval <float> (default .05) - Number of seconds in between each poll
 
    @return - Returncode of application, or None if did not terminate.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
call(*popenargs, **kwargs)
Run command with arguments.  Wait for command to complete, then
return the returncode attribute.
 
The arguments are the same as for the Popen constructor.  Example:
 
retcode = call(["ls", "-l"])
check_call(*popenargs, **kwargs)
Run command with arguments.  Wait for command to complete.  If
the exit code was zero then return, otherwise raise
CalledProcessError.  The CalledProcessError object will have the
return code in the returncode attribute.
 
The arguments are the same as for the Popen constructor.  Example:
 
check_call(["ls", "-l"])
check_output(*popenargs, **kwargs)
Run command with arguments and return its output as a byte string.
 
If the exit code was non-zero it raises a CalledProcessError.  The
CalledProcessError object will have the return code in the returncode
attribute and output in the output attribute.
 
The arguments are the same as for the Popen constructor.  Example:
 
>>> check_output(["ls", "-l", "/dev/null"])
'crw-rw-rw- 1 root root 1, 3 Oct 18  2007 /dev/null\n'
 
The stdout argument is not allowed as it is used internally.
To capture standard error in the result, use stderr=STDOUT.
 
>>> check_output(["/bin/sh", "-c",
...               "ls -l non_existent_file ; exit 0"],
...              stderr=STDOUT)
'ls: non_existent_file: No such file or directory\n'

 
Data
        DEFAULT_POLL_INTERVAL = 0.05
PIPE = -1
STDOUT = -2
SUBPROCESS2_DEFAULT_TERMINATE_TO_KILL_SECONDS = 1.5
SUBPROCESS2_PROCESS_COMPLETED = 0
SUBPROCESS2_PROCESS_KILLED = 2
SUBPROCESS2_PROCESS_TERMINATED = 1
__all__ = ['check_output', 'SUBPROCESS2_PROCESS_TERMINATED', 'STDOUT', 'SUBPROCESS2_PROCESS_KILLED', 'Popen', 'DEFAULT_POLL_INTERVAL', 'subprocess2_version', 'PIPE', 'SUBPROCESS2_DEFAULT_TERMINATE_TO_KILL_SECONDS', 'call', 'subprocess2_version_tuple', 'check_call', 'CalledProcessError', 'SUBPROCESS2_PROCESS_COMPLETED']
subprocess2_version = '0.2.1'
subprocess2_version_tuple = (0, 2, 1)