Back to index

python3.2  3.2.2
Classes | Functions | Variables
multiprocessing.util Namespace Reference

Classes

class  Finalize
class  ForkAwareThreadLock
class  ForkAwareLocal

Functions

def sub_debug
def debug
def info
def sub_warning
def get_logger
def log_to_stderr
def get_temp_dir
def _run_after_forkers
def register_after_fork
def _run_finalizers
def is_exiting
def _exit_function

Variables

list __all__
int NOTSET = 0
int SUBDEBUG = 5
int DEBUG = 10
int INFO = 20
int SUBWARNING = 25
string LOGGER_NAME = 'multiprocessing'
string DEFAULT_LOGGING_FORMAT = '[%(levelname)s/%(processName)s] %(message)s'
 _logger = None
 _log_to_stderr = False
tuple _afterfork_registry = weakref.WeakValueDictionary()
tuple _afterfork_counter = itertools.count()
dictionary _finalizer_registry = {}
tuple _finalizer_counter = itertools.count()
 _exiting = False

Function Documentation

Definition at line 281 of file util.py.

00281 
00282 def _exit_function():
00283     global _exiting
00284 
00285     info('process shutting down')
00286     debug('running all "atexit" finalizers with priority >= 0')
00287     _run_finalizers(0)
00288 
00289     for p in active_children():
00290         if p._daemonic:
00291             info('calling terminate() for daemon %s', p.name)
00292             p._popen.terminate()
00293 
00294     for p in active_children():
00295         info('calling join() for process %s', p.name)
00296         p.join()
00297 
00298     debug('running the remaining "atexit" finalizers')
00299     _run_finalizers()
00300 
00301 atexit.register(_exit_function)
00302 
00303 #
00304 # Some fork aware types
00305 #

Here is the call graph for this function:

Definition at line 150 of file util.py.

00150 
00151 def _run_after_forkers():
00152     items = list(_afterfork_registry.items())
00153     items.sort()
00154     for (index, ident, func), obj in items:
00155         try:
00156             func(obj)
00157         except Exception as e:
00158             info('after forker raised exception %s', e)

def multiprocessing.util._run_finalizers (   minpriority = None) [private]
Run all finalizers whose exit priority is not None and at least minpriority

Finalizers with highest priority are called first; finalizers with
the same priority will be called in reverse order of creation.

Definition at line 243 of file util.py.

00243 
00244 def _run_finalizers(minpriority=None):
00245     '''
00246     Run all finalizers whose exit priority is not None and at least minpriority
00247 
00248     Finalizers with highest priority are called first; finalizers with
00249     the same priority will be called in reverse order of creation.
00250     '''
00251     if minpriority is None:
00252         f = lambda p : p[0][0] is not None
00253     else:
00254         f = lambda p : p[0][0] is not None and p[0][0] >= minpriority
00255 
00256     items = [x for x in list(_finalizer_registry.items()) if f(x)]
00257     items.sort(reverse=True)
00258 
00259     for key, finalizer in items:
00260         sub_debug('calling %s', finalizer)
00261         try:
00262             finalizer()
00263         except Exception:
00264             import traceback
00265             traceback.print_exc()
00266 
00267     if minpriority is None:
00268         _finalizer_registry.clear()
00269 
00270 #
00271 # Clean up on exit
00272 #

Here is the call graph for this function:

Here is the caller graph for this function:

def multiprocessing.util.debug (   msg,
  args 
)

Definition at line 70 of file util.py.

00070 
00071 def debug(msg, *args):
00072     if _logger:
00073         _logger.log(DEBUG, msg, *args)

Here is the caller graph for this function:

Returns logger used by multiprocessing

Definition at line 82 of file util.py.

00082 
00083 def get_logger():
00084     '''
00085     Returns logger used by multiprocessing
00086     '''
00087     global _logger
00088     import logging, atexit
00089 
00090     logging._acquireLock()
00091     try:
00092         if not _logger:
00093 
00094             _logger = logging.getLogger(LOGGER_NAME)
00095             _logger.propagate = 0
00096             logging.addLevelName(SUBDEBUG, 'SUBDEBUG')
00097             logging.addLevelName(SUBWARNING, 'SUBWARNING')
00098 
00099             # XXX multiprocessing should cleanup before logging
00100             if hasattr(atexit, 'unregister'):
00101                 atexit.unregister(_exit_function)
00102                 atexit.register(_exit_function)
00103             else:
00104                 atexit._exithandlers.remove((_exit_function, (), {}))
00105                 atexit._exithandlers.append((_exit_function, (), {}))
00106 
00107     finally:
00108         logging._releaseLock()
00109 
00110     return _logger

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 133 of file util.py.

00133 
00134 def get_temp_dir():
00135     # get name of a temp directory which will be automatically cleaned up
00136     if current_process()._tempdir is None:
00137         import shutil, tempfile
00138         tempdir = tempfile.mkdtemp(prefix='pymp-')
00139         info('created temp directory %s', tempdir)
00140         Finalize(None, shutil.rmtree, args=[tempdir], exitpriority=-100)
00141         current_process()._tempdir = tempdir
00142     return current_process()._tempdir
00143 
00144 #
00145 # Support for reinitialization of objects when bootstrapping a child process
00146 #

Here is the call graph for this function:

Here is the caller graph for this function:

def multiprocessing.util.info (   msg,
  args 
)

Definition at line 74 of file util.py.

00074 
00075 def info(msg, *args):
00076     if _logger:
00077         _logger.log(INFO, msg, *args)

Returns true if the process is shutting down

Definition at line 273 of file util.py.

00273 
00274 def is_exiting():
00275     '''
00276     Returns true if the process is shutting down
00277     '''
00278     return _exiting or _exiting is None

Here is the caller graph for this function:

def multiprocessing.util.log_to_stderr (   level = None)
Turn on logging and add a handler which prints to stderr

Definition at line 111 of file util.py.

00111 
00112 def log_to_stderr(level=None):
00113     '''
00114     Turn on logging and add a handler which prints to stderr
00115     '''
00116     global _log_to_stderr
00117     import logging
00118 
00119     logger = get_logger()
00120     formatter = logging.Formatter(DEFAULT_LOGGING_FORMAT)
00121     handler = logging.StreamHandler()
00122     handler.setFormatter(formatter)
00123     logger.addHandler(handler)
00124 
00125     if level:
00126         logger.setLevel(level)
00127     _log_to_stderr = True
00128     return _logger
00129 
00130 #
00131 # Function returning a temp directory which will be removed on exit
00132 #

Here is the call graph for this function:

def multiprocessing.util.register_after_fork (   obj,
  func 
)

Definition at line 159 of file util.py.

00159 
00160 def register_after_fork(obj, func):
00161     _afterfork_registry[(next(_afterfork_counter), id(obj), func)] = obj
00162 
00163 #
00164 # Finalization using weakrefs
00165 #

Here is the caller graph for this function:

def multiprocessing.util.sub_debug (   msg,
  args 
)

Definition at line 66 of file util.py.

00066 
00067 def sub_debug(msg, *args):
00068     if _logger:
00069         _logger.log(SUBDEBUG, msg, *args)

Here is the caller graph for this function:

def multiprocessing.util.sub_warning (   msg,
  args 
)

Definition at line 78 of file util.py.

00078 
00079 def sub_warning(msg, *args):
00080     if _logger:
00081         _logger.log(SUBWARNING, msg, *args)

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 [
00002     'sub_debug', 'debug', 'info', 'sub_warning', 'get_logger',
00003     'log_to_stderr', 'get_temp_dir', 'register_after_fork',
00004     'is_exiting', 'Finalize', 'ForkAwareThreadLock', 'ForkAwareLocal',
00005     'SUBDEBUG', 'SUBWARNING',
00006     ]

Definition at line 43 of file util.py.

Definition at line 148 of file util.py.

Definition at line 147 of file util.py.

Definition at line 279 of file util.py.

Definition at line 167 of file util.py.

Definition at line 166 of file util.py.

Definition at line 64 of file util.py.

Definition at line 63 of file util.py.

Definition at line 56 of file util.py.

string multiprocessing.util.DEFAULT_LOGGING_FORMAT = '[%(levelname)s/%(processName)s] %(message)s'

Definition at line 61 of file util.py.

Definition at line 57 of file util.py.

Definition at line 60 of file util.py.

Definition at line 54 of file util.py.

Definition at line 55 of file util.py.

Definition at line 58 of file util.py.