Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
multiprocessing.process.Process Class Reference
Inheritance diagram for multiprocessing.process.Process:
Inheritance graph
[legend]
Collaboration diagram for multiprocessing.process.Process:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def run
def start
def terminate
def join
def is_alive
def name
def name
def daemon
def daemon
def authkey
def authkey
def exitcode
def ident
def __repr__

Public Attributes

_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Static Public Attributes

 pid = ident

Private Member Functions

def _bootstrap

Private Attributes

 _identity
 _authkey
 _daemonic
 _tempdir
 _parent_pid
 _popen
 _target
 _args
 _kwargs
 _name
 _children
 _counter

Static Private Attributes

 _Popen = None

Detailed Description

Process objects represent activity that is run in a separate process

The class is analagous to `threading.Thread`

Definition at line 87 of file process.py.


Constructor & Destructor Documentation

def multiprocessing.process.Process.__init__ (   self,
  group = None,
  target = None,
  name = None,
  args = (),
  kwargs = {} 
)

Definition at line 95 of file process.py.

00095 
00096     def __init__(self, group=None, target=None, name=None, args=(), kwargs={}):
00097         assert group is None, 'group argument must be None for now'
00098         count = next(_current_process._counter)
00099         self._identity = _current_process._identity + (count,)
00100         self._authkey = _current_process._authkey
00101         self._daemonic = _current_process._daemonic
00102         self._tempdir = _current_process._tempdir
00103         self._parent_pid = os.getpid()
00104         self._popen = None
00105         self._target = target
00106         self._args = tuple(args)
00107         self._kwargs = dict(kwargs)
00108         self._name = name or type(self).__name__ + '-' + \
00109                      ':'.join(str(i) for i in self._identity)
00110         _dangling.add(self)

Here is the caller graph for this function:


Member Function Documentation

Definition at line 219 of file process.py.

00219 
00220     def __repr__(self):
00221         if self is _current_process:
00222             status = 'started'
00223         elif self._parent_pid != os.getpid():
00224             status = 'unknown'
00225         elif self._popen is None:
00226             status = 'initial'
00227         else:
00228             if self._popen.poll() is not None:
00229                 status = self.exitcode
00230             else:
00231                 status = 'started'
00232 
00233         if type(status) is int:
00234             if status == 0:
00235                 status = 'stopped'
00236             else:
00237                 status = 'stopped[%s]' % _exitcode_to_name.get(status, status)
00238 
00239         return '<%s(%s, %s%s)>' % (type(self).__name__, self._name,
00240                                    status, self._daemonic and ' daemon' or '')

Here is the call graph for this function:

Definition at line 243 of file process.py.

00243 
00244     def _bootstrap(self):
00245         from . import util
00246         global _current_process
00247 
00248         try:
00249             self._children = set()
00250             self._counter = itertools.count(1)
00251             if sys.stdin is not None:
00252                 try:
00253                     sys.stdin.close()
00254                     sys.stdin = open(os.devnull)
00255                 except (OSError, ValueError):
00256                     pass
00257             old_process = _current_process
00258             _current_process = self
00259             try:
00260                 util._finalizer_registry.clear()
00261                 util._run_after_forkers()
00262             finally:
00263                 # delay finalization of the old process object until after
00264                 # _run_after_forkers() is executed
00265                 del old_process
00266             util.info('child process calling self.run()')
00267             try:
00268                 self.run()
00269                 exitcode = 0
00270             finally:
00271                 util._exit_function()
00272         except SystemExit as e:
00273             if not e.args:
00274                 exitcode = 1
00275             elif type(e.args[0]) is int:
00276                 exitcode = e.args[0]
00277             else:
00278                 sys.stderr.write(e.args[0] + '\n')
00279                 sys.stderr.flush()
00280                 exitcode = 1
00281         except:
00282             exitcode = 1
00283             import traceback
00284             sys.stderr.write('Process %s:\n' % self.name)
00285             sys.stderr.flush()
00286             traceback.print_exc()
00287 
00288         util.info('process exiting with exitcode %d' % exitcode)
00289         return exitcode
00290 
00291 #
00292 # We subclass bytes to avoid accidental transmission of auth keys over network
00293 #

Here is the caller graph for this function:

Definition at line 188 of file process.py.

00188 
00189     def authkey(self):
00190         return self._authkey

Here is the caller graph for this function:

def multiprocessing.process.Process.authkey (   self,
  authkey 
)
Set authorization key of process

Definition at line 192 of file process.py.

00192 
00193     def authkey(self, authkey):
00194         '''
00195         Set authorization key of process
00196         '''
00197         self._authkey = AuthenticationString(authkey)

Here is the call graph for this function:

Return whether process is a daemon

Definition at line 173 of file process.py.

00173 
00174     def daemon(self):
00175         '''
00176         Return whether process is a daemon
00177         '''
00178         return self._daemonic

Here is the caller graph for this function:

def multiprocessing.process.Process.daemon (   self,
  daemonic 
)
Set whether process is a daemon

Definition at line 180 of file process.py.

00180 
00181     def daemon(self, daemonic):
00182         '''
00183         Set whether process is a daemon
00184         '''
00185         assert self._popen is None, 'process has already started'
00186         self._daemonic = daemonic

Here is the call graph for this function:

Return exit code of process or `None` if it has yet to stop

Definition at line 199 of file process.py.

00199 
00200     def exitcode(self):
00201         '''
00202         Return exit code of process or `None` if it has yet to stop
00203         '''
00204         if self._popen is None:
00205             return self._popen
00206         return self._popen.poll()

Here is the caller graph for this function:

Return identifier (PID) of process or `None` if it has yet to start

Definition at line 208 of file process.py.

00208 
00209     def ident(self):
00210         '''
00211         Return identifier (PID) of process or `None` if it has yet to start
00212         '''
00213         if self is _current_process:
00214             return os.getpid()
00215         else:
00216             return self._popen and self._popen.pid

Return whether process is alive

Definition at line 151 of file process.py.

00151 
00152     def is_alive(self):
00153         '''
00154         Return whether process is alive
00155         '''
00156         if self is _current_process:
00157             return True
00158         assert self._parent_pid == os.getpid(), 'can only test a child process'
00159         if self._popen is None:
00160             return False
00161         self._popen.poll()
00162         return self._popen.returncode is None

Here is the caller graph for this function:

def multiprocessing.process.Process.join (   self,
  timeout = None 
)
Wait until child process terminates

Definition at line 141 of file process.py.

00141 
00142     def join(self, timeout=None):
00143         '''
00144         Wait until child process terminates
00145         '''
00146         assert self._parent_pid == os.getpid(), 'can only join a child process'
00147         assert self._popen is not None, 'can only join a started process'
00148         res = self._popen.wait(timeout)
00149         if res is not None:
00150             _current_process._children.discard(self)

Here is the caller graph for this function:

Definition at line 164 of file process.py.

00164 
00165     def name(self):
00166         return self._name

Here is the caller graph for this function:

def multiprocessing.process.Process.name (   self,
  name 
)

Definition at line 168 of file process.py.

00168 
00169     def name(self, name):
00170         assert isinstance(name, str), 'name must be a string'
00171         self._name = name

Here is the call graph for this function:

Here is the caller graph for this function:

Method to be run in sub-process; can be overridden in sub-class

Reimplemented in test.test_multiprocessing._UpperCaser.

Definition at line 111 of file process.py.

00111 
00112     def run(self):
00113         '''
00114         Method to be run in sub-process; can be overridden in sub-class
00115         '''
00116         if self._target:
00117             self._target(*self._args, **self._kwargs)

Here is the caller graph for this function:

Start child process

Definition at line 118 of file process.py.

00118 
00119     def start(self):
00120         '''
00121         Start child process
00122         '''
00123         assert self._popen is None, 'cannot start a process twice'
00124         assert self._parent_pid == os.getpid(), \
00125                'can only start a process object created by current process'
00126         assert not _current_process._daemonic, \
00127                'daemonic processes are not allowed to have children'
00128         _cleanup()
00129         if self._Popen is not None:
00130             Popen = self._Popen
00131         else:
00132             from .forking import Popen
00133         self._popen = Popen(self)
00134         _current_process._children.add(self)

Here is the call graph for this function:

Here is the caller graph for this function:

Terminate process; sends SIGTERM signal or uses TerminateProcess()

Definition at line 135 of file process.py.

00135 
00136     def terminate(self):
00137         '''
00138         Terminate process; sends SIGTERM signal or uses TerminateProcess()
00139         '''
00140         self._popen.terminate()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 105 of file process.py.

Reimplemented in multiprocessing.process._MainProcess.

Definition at line 99 of file process.py.

Reimplemented in multiprocessing.process._MainProcess.

Definition at line 248 of file process.py.

Reimplemented in multiprocessing.process._MainProcess.

Definition at line 249 of file process.py.

Reimplemented in multiprocessing.process._MainProcess.

Definition at line 100 of file process.py.

Reimplemented in multiprocessing.process._MainProcess.

Definition at line 98 of file process.py.

Definition at line 106 of file process.py.

Reimplemented in multiprocessing.process._MainProcess.

Definition at line 107 of file process.py.

Reimplemented in multiprocessing.process._MainProcess.

Definition at line 102 of file process.py.

multiprocessing.process.Process._Popen = None [static, private]

Definition at line 93 of file process.py.

Reimplemented in multiprocessing.process._MainProcess.

Definition at line 103 of file process.py.

Definition at line 104 of file process.py.

Reimplemented in multiprocessing.process._MainProcess.

Definition at line 101 of file process.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 217 of file process.py.


The documentation for this class was generated from the following file: