Back to index

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

List of all members.

Public Member Functions

def __init__
def __call__
def cancel
def still_active
def __repr__

Public Attributes

_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Attributes

 _weakref
 _callback
 _args
 _kwargs
 _key

Detailed Description

Class which supports object finalization using weakrefs

Definition at line 170 of file util.py.


Constructor & Destructor Documentation

def multiprocessing.util.Finalize.__init__ (   self,
  obj,
  callback,
  args = (),
  kwargs = None,
  exitpriority = None 
)

Definition at line 174 of file util.py.

00174 
00175     def __init__(self, obj, callback, args=(), kwargs=None, exitpriority=None):
00176         assert exitpriority is None or type(exitpriority) is int
00177 
00178         if obj is not None:
00179             self._weakref = weakref.ref(obj, self)
00180         else:
00181             assert exitpriority is not None
00182 
00183         self._callback = callback
00184         self._args = args
00185         self._kwargs = kwargs or {}
00186         self._key = (exitpriority, next(_finalizer_counter))
00187 
00188         _finalizer_registry[self._key] = self

Here is the caller graph for this function:


Member Function Documentation

def multiprocessing.util.Finalize.__call__ (   self,
  wr = None 
)
Run the callback unless it has already been called or cancelled

Definition at line 189 of file util.py.

00189 
00190     def __call__(self, wr=None):
00191         '''
00192         Run the callback unless it has already been called or cancelled
00193         '''
00194         try:
00195             del _finalizer_registry[self._key]
00196         except KeyError:
00197             sub_debug('finalizer no longer registered')
00198         else:
00199             sub_debug('finalizer calling %s with args %s and kwargs %s',
00200                      self._callback, self._args, self._kwargs)
00201             res = self._callback(*self._args, **self._kwargs)
00202             self._weakref = self._callback = self._args = \
00203                             self._kwargs = self._key = None
00204             return res

Here is the call graph for this function:

Definition at line 223 of file util.py.

00223 
00224     def __repr__(self):
00225         try:
00226             obj = self._weakref()
00227         except (AttributeError, TypeError):
00228             obj = None
00229 
00230         if obj is None:
00231             return '<Finalize object, dead>'
00232 
00233         x = '<Finalize object, callback=%s' % \
00234             getattr(self._callback, '__name__', self._callback)
00235         if self._args:
00236             x += ', args=' + str(self._args)
00237         if self._kwargs:
00238             x += ', kwargs=' + str(self._kwargs)
00239         if self._key[0] is not None:
00240             x += ', exitprority=' + str(self._key[0])
00241         return x + '>'
00242 

Here is the call graph for this function:

Cancel finalization of the object

Definition at line 205 of file util.py.

00205 
00206     def cancel(self):
00207         '''
00208         Cancel finalization of the object
00209         '''
00210         try:
00211             del _finalizer_registry[self._key]
00212         except KeyError:
00213             pass
00214         else:
00215             self._weakref = self._callback = self._args = \
00216                             self._kwargs = self._key = None

Here is the caller graph for this function:

Return whether this finalizer is still waiting to invoke callback

Definition at line 217 of file util.py.

00217 
00218     def still_active(self):
00219         '''
00220         Return whether this finalizer is still waiting to invoke callback
00221         '''
00222         return self._key in _finalizer_registry


Member Data Documentation

Definition at line 183 of file util.py.

Definition at line 182 of file util.py.

Definition at line 185 of file util.py.

Definition at line 184 of file util.py.

Definition at line 178 of file util.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.


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