Back to index

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

List of all members.

Public Member Functions

def __init__
def poll
def wait
def terminate
def __init__
def wait
def poll
def terminate

Static Public Member Functions

def thread_is_spawning
def thread_is_spawning
def duplicate_for_child

Public Attributes

 returncode
 pid
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Attributes

 _handle

Static Private Attributes

tuple _tls = _thread._local()

Detailed Description

Start a subprocess to run the code of a process object

Definition at line 114 of file forking.py.


Constructor & Destructor Documentation

def multiprocessing.forking.Popen.__init__ (   self,
  process_obj 
)

Definition at line 116 of file forking.py.

00116 
00117         def __init__(self, process_obj):
00118             sys.stdout.flush()
00119             sys.stderr.flush()
00120             self.returncode = None
00121 
00122             self.pid = os.fork()
00123             if self.pid == 0:
00124                 if 'random' in sys.modules:
00125                     import random
00126                     random.seed()
00127                 code = process_obj._bootstrap()
00128                 sys.stdout.flush()
00129                 sys.stderr.flush()
00130                 os._exit(code)

Here is the caller graph for this function:

def multiprocessing.forking.Popen.__init__ (   self,
  process_obj 
)

Definition at line 240 of file forking.py.

00240 
00241         def __init__(self, process_obj):
00242             # create pipe for communication with child
00243             rfd, wfd = os.pipe()
00244 
00245             # get handle for read end of the pipe and make it inheritable
00246             rhandle = duplicate(msvcrt.get_osfhandle(rfd), inheritable=True)
00247             os.close(rfd)
00248 
00249             # start process
00250             cmd = get_command_line() + [rhandle]
00251             cmd = ' '.join('"%s"' % x for x in cmd)
00252             hp, ht, pid, tid = _subprocess.CreateProcess(
00253                 _python_exe, cmd, None, None, 1, 0, None, None, None
00254                 )
00255             ht.Close()
00256             close(rhandle)
00257 
00258             # set attributes of self
00259             self.pid = pid
00260             self.returncode = None
00261             self._handle = hp
00262 
00263             # send information to child
00264             prep_data = get_preparation_data(process_obj._name)
00265             to_child = os.fdopen(wfd, 'wb')
00266             Popen._tls.process_handle = int(hp)
00267             try:
00268                 dump(prep_data, to_child, HIGHEST_PROTOCOL)
00269                 dump(process_obj, to_child, HIGHEST_PROTOCOL)
00270             finally:
00271                 del Popen._tls.process_handle
00272                 to_child.close()

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

Definition at line 278 of file forking.py.

00278 
00279         def duplicate_for_child(handle):
00280             return duplicate(handle, Popen._tls.process_handle)

def multiprocessing.forking.Popen.poll (   self,
  flag = os.WNOHANG 
)

Definition at line 131 of file forking.py.

00131 
00132         def poll(self, flag=os.WNOHANG):
00133             if self.returncode is None:
00134                 try:
00135                     pid, sts = os.waitpid(self.pid, flag)
00136                 except os.error:
00137                     # Child process not yet created. See #1731717
00138                     # e.errno == errno.ECHILD == 10
00139                     return None
00140                 if pid == self.pid:
00141                     if os.WIFSIGNALED(sts):
00142                         self.returncode = -os.WTERMSIG(sts)
00143                     else:
00144                         assert os.WIFEXITED(sts)
00145                         self.returncode = os.WEXITSTATUS(sts)
00146             return self.returncode

Here is the caller graph for this function:

Definition at line 297 of file forking.py.

00297 
00298         def poll(self):
00299             return self.wait(timeout=0)

Here is the call graph for this function:

Definition at line 163 of file forking.py.

00163 
00164         def terminate(self):
00165             if self.returncode is None:
00166                 try:
00167                     os.kill(self.pid, signal.SIGTERM)
00168                 except OSError as e:
00169                     if self.wait(timeout=0.1) is None:
00170                         raise

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 300 of file forking.py.

00300 
00301         def terminate(self):
00302             if self.returncode is None:
00303                 try:
00304                     _subprocess.TerminateProcess(int(self._handle), TERMINATE)
00305                 except WindowsError:
00306                     if self.wait(timeout=0.1) is None:
00307                         raise
00308 
    #

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 172 of file forking.py.

00172 
00173         def thread_is_spawning():
00174             return False
00175 
00176 #
00177 # Windows
00178 #
00179 
00180 else:
    import _thread

Here is the caller graph for this function:

Definition at line 274 of file forking.py.

00274 
00275         def thread_is_spawning():
00276             return getattr(Popen._tls, 'process_handle', None) is not None

Here is the call graph for this function:

def multiprocessing.forking.Popen.wait (   self,
  timeout = None 
)

Definition at line 147 of file forking.py.

00147 
00148         def wait(self, timeout=None):
00149             if timeout is None:
00150                 return self.poll(0)
00151             deadline = time.time() + timeout
00152             delay = 0.0005
00153             while 1:
00154                 res = self.poll()
00155                 if res is not None:
00156                     break
00157                 remaining = deadline - time.time()
00158                 if remaining <= 0:
00159                     break
00160                 delay = min(delay * 2, remaining, 0.05)
00161                 time.sleep(delay)
00162             return res

Here is the call graph for this function:

Here is the caller graph for this function:

def multiprocessing.forking.Popen.wait (   self,
  timeout = None 
)

Definition at line 281 of file forking.py.

00281 
00282         def wait(self, timeout=None):
00283             if self.returncode is None:
00284                 if timeout is None:
00285                     msecs = _subprocess.INFINITE
00286                 else:
00287                     msecs = max(0, int(timeout * 1000 + 0.5))
00288 
00289                 res = _subprocess.WaitForSingleObject(int(self._handle), msecs)
00290                 if res == _subprocess.WAIT_OBJECT_0:
00291                     code = _subprocess.GetExitCodeProcess(self._handle)
00292                     if code == TERMINATE:
00293                         code = -signal.SIGTERM
00294                     self.returncode = code
00295 
00296             return self.returncode

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 260 of file forking.py.

tuple multiprocessing.forking.Popen._tls = _thread._local() [static, private]

Definition at line 238 of file forking.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 121 of file forking.py.

Definition at line 119 of file forking.py.


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