Back to index

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

List of all members.

Public Member Functions

def __init__
def __reduce__
def __deepcopy__
def __repr__
def __str__

Public Attributes

_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def _connect
def _callmethod
def _getvalue
def _incref
def _after_fork

Static Private Member Functions

def _decref

Private Attributes

 _tls
 _idset
 _token
 _id
 _manager
 _serializer
 _Client
 _authkey
 _close

Static Private Attributes

dictionary _address_to_local = {}
tuple _mutex = util.ForkAwareThreadLock()

Detailed Description

A base for proxies of shared objects

Definition at line 695 of file managers.py.


Constructor & Destructor Documentation

def multiprocessing.managers.BaseProxy.__init__ (   self,
  token,
  serializer,
  manager = None,
  authkey = None,
  exposed = None,
  incref = True 
)

Definition at line 703 of file managers.py.

00703 
00704                  authkey=None, exposed=None, incref=True):
00705         BaseProxy._mutex.acquire()
00706         try:
00707             tls_idset = BaseProxy._address_to_local.get(token.address, None)
00708             if tls_idset is None:
00709                 tls_idset = util.ForkAwareLocal(), ProcessLocalSet()
00710                 BaseProxy._address_to_local[token.address] = tls_idset
00711         finally:
00712             BaseProxy._mutex.release()
00713 
00714         # self._tls is used to record the connection used by this
00715         # thread to communicate with the manager at token.address
00716         self._tls = tls_idset[0]
00717 
00718         # self._idset is used to record the identities of all shared
00719         # objects for which the current process owns references and
00720         # which are in the manager at token.address
00721         self._idset = tls_idset[1]
00722 
00723         self._token = token
00724         self._id = self._token.id
00725         self._manager = manager
00726         self._serializer = serializer
00727         self._Client = listener_client[serializer][1]
00728 
00729         if authkey is not None:
00730             self._authkey = AuthenticationString(authkey)
00731         elif self._manager is not None:
00732             self._authkey = self._manager._authkey
00733         else:
00734             self._authkey = current_process().authkey
00735 
00736         if incref:
00737             self._incref()
00738 
00739         util.register_after_fork(self, BaseProxy._after_fork)

Here is the caller graph for this function:


Member Function Documentation

Definition at line 846 of file managers.py.

00846 
00847     def __deepcopy__(self, memo):
00848         return self._getvalue()

Here is the call graph for this function:

Definition at line 833 of file managers.py.

00833 
00834     def __reduce__(self):
00835         kwds = {}
00836         if Popen.thread_is_spawning():
00837             kwds['authkey'] = self._authkey
00838 
00839         if getattr(self, '_isauto', False):
00840             kwds['exposed'] = self._exposed_
00841             return (RebuildProxy,
00842                     (AutoProxy, self._token, self._serializer, kwds))
00843         else:
00844             return (RebuildProxy,
00845                     (type(self), self._token, self._serializer, kwds))

Here is the call graph for this function:

Definition at line 849 of file managers.py.

00849 
00850     def __repr__(self):
00851         return '<%s object, typeid %r at %s>' % \
00852                (type(self).__name__, self._token.typeid, '0x%x' % id(self))

Return representation of the referent (or a fall-back if that fails)

Definition at line 853 of file managers.py.

00853 
00854     def __str__(self):
00855         '''
00856         Return representation of the referent (or a fall-back if that fails)
00857         '''
00858         try:
00859             return self._callmethod('__repr__')
00860         except Exception:
00861             return repr(self)[:-1] + "; '__str__()' failed>"
00862 
00863 #
00864 # Function used for unpickling
00865 #

Here is the call graph for this function:

Definition at line 825 of file managers.py.

00825 
00826     def _after_fork(self):
00827         self._manager = None
00828         try:
00829             self._incref()
00830         except Exception as e:
00831             # the proxy may just be for a manager which has shutdown
00832             util.info('incref failed: %s' % e)

Here is the call graph for this function:

Here is the caller graph for this function:

def multiprocessing.managers.BaseProxy._callmethod (   self,
  methodname,
  args = (),
  kwds = {} 
) [private]
Try to call a method of the referrent and return a copy of the result

Definition at line 749 of file managers.py.

00749 
00750     def _callmethod(self, methodname, args=(), kwds={}):
00751         '''
00752         Try to call a method of the referrent and return a copy of the result
00753         '''
00754         try:
00755             conn = self._tls.connection
00756         except AttributeError:
00757             util.debug('thread %r does not own a connection',
00758                        threading.current_thread().name)
00759             self._connect()
00760             conn = self._tls.connection
00761 
00762         conn.send((self._id, methodname, args, kwds))
00763         kind, result = conn.recv()
00764 
00765         if kind == '#RETURN':
00766             return result
00767         elif kind == '#PROXY':
00768             exposed, token = result
00769             proxytype = self._manager._registry[token.typeid][-1]
00770             proxy = proxytype(
00771                 token, self._serializer, manager=self._manager,
00772                 authkey=self._authkey, exposed=exposed
00773                 )
00774             conn = self._Client(token.address, authkey=self._authkey)
00775             dispatch(conn, None, 'decref', (token.id,))
00776             return proxy
00777         raise convert_to_error(kind, result)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 740 of file managers.py.

00740 
00741     def _connect(self):
00742         util.debug('making connection to manager')
00743         name = current_process().name
00744         if threading.current_thread().name != 'MainThread':
00745             name += '|' + threading.current_thread().name
00746         conn = self._Client(self._token.address, authkey=self._authkey)
00747         dispatch(conn, None, 'accept_connection', (name,))
00748         self._tls.connection = conn

Here is the call graph for this function:

Here is the caller graph for this function:

def multiprocessing.managers.BaseProxy._decref (   token,
  authkey,
  state,
  tls,
  idset,
  _Client 
) [static, private]

Definition at line 801 of file managers.py.

00801 
00802     def _decref(token, authkey, state, tls, idset, _Client):
00803         idset.discard(token.id)
00804 
00805         # check whether manager is still alive
00806         if state is None or state.value == State.STARTED:
00807             # tell manager this process no longer cares about referent
00808             try:
00809                 util.debug('DECREF %r', token.id)
00810                 conn = _Client(token.address, authkey=authkey)
00811                 dispatch(conn, None, 'decref', (token.id,))
00812             except Exception as e:
00813                 util.debug('... decref failed %s', e)
00814 
00815         else:
00816             util.debug('DECREF %r -- manager already shutdown', token.id)
00817 
00818         # check whether we can close this thread's connection because
00819         # the process owns no more references to objects for this manager
00820         if not idset and hasattr(tls, 'connection'):
00821             util.debug('thread %r has no more proxies so closing conn',
00822                        threading.current_thread().name)
00823             tls.connection.close()
00824             del tls.connection

Here is the call graph for this function:

Get a copy of the value of the referent

Definition at line 778 of file managers.py.

00778 
00779     def _getvalue(self):
00780         '''
00781         Get a copy of the value of the referent
00782         '''
00783         return self._callmethod('#GETVALUE')

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 784 of file managers.py.

00784 
00785     def _incref(self):
00786         conn = self._Client(self._token.address, authkey=self._authkey)
00787         dispatch(conn, None, 'incref', (self._id,))
00788         util.debug('INCREF %r', self._token.id)
00789 
00790         self._idset.add(self._id)
00791 
00792         state = self._manager and self._manager._state
00793 
00794         self._close = util.Finalize(
00795             self, BaseProxy._decref,
00796             args=(self._token, self._authkey, state,
00797                   self._tls, self._idset, self._Client),
00798             exitpriority=10
00799             )

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 699 of file managers.py.

Definition at line 729 of file managers.py.

Definition at line 726 of file managers.py.

Definition at line 793 of file managers.py.

Definition at line 723 of file managers.py.

Definition at line 720 of file managers.py.

Definition at line 724 of file managers.py.

Definition at line 700 of file managers.py.

Definition at line 725 of file managers.py.

Definition at line 715 of file managers.py.

Definition at line 722 of file managers.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: