Back to index

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

List of all members.

Public Member Functions

def __init__
def __reduce__
def get_server
def connect
def start
def join
def __enter__
def __exit__
def register

Public Attributes

 shutdown
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Properties

 address = property(lambda self: self._address)

Private Member Functions

def _run_server
def _create
def _debug_info
def _number_of_objects

Static Private Member Functions

def _finalize_manager

Private Attributes

 _address
 _authkey
 _state
 _serializer
 _Client
 _process

Static Private Attributes

dictionary _registry = {}
 _Server = Server

Detailed Description

Base class for managers

Definition at line 469 of file managers.py.


Constructor & Destructor Documentation

def multiprocessing.managers.BaseManager.__init__ (   self,
  address = None,
  authkey = None,
  serializer = 'pickle' 
)

Definition at line 476 of file managers.py.

00476 
00477     def __init__(self, address=None, authkey=None, serializer='pickle'):
00478         if authkey is None:
00479             authkey = current_process().authkey
00480         self._address = address     # XXX not final address if eg ('', 0)
00481         self._authkey = AuthenticationString(authkey)
00482         self._state = State()
00483         self._state.value = State.INITIAL
00484         self._serializer = serializer
00485         self._Listener, self._Client = listener_client[serializer]

Here is the caller graph for this function:


Member Function Documentation

Definition at line 601 of file managers.py.

00601 
00602     def __enter__(self):
00603         return self

def multiprocessing.managers.BaseManager.__exit__ (   self,
  exc_type,
  exc_val,
  exc_tb 
)

Definition at line 604 of file managers.py.

00604 
00605     def __exit__(self, exc_type, exc_val, exc_tb):
00606         self.shutdown()

Here is the caller graph for this function:

Definition at line 486 of file managers.py.

00486 
00487     def __reduce__(self):
00488         return type(self).from_address, \
00489                (self._address, self._authkey, self._serializer)

def multiprocessing.managers.BaseManager._create (   self,
  typeid,
  args,
  kwds 
) [private]
Create a new shared object; return the token and exposed tuple

Definition at line 563 of file managers.py.

00563 
00564     def _create(self, typeid, *args, **kwds):
00565         '''
00566         Create a new shared object; return the token and exposed tuple
00567         '''
00568         assert self._state.value == State.STARTED, 'server not yet started'
00569         conn = self._Client(self._address, authkey=self._authkey)
00570         try:
00571             id, exposed = dispatch(conn, None, 'create', (typeid,)+args, kwds)
00572         finally:
00573             conn.close()
00574         return Token(typeid, self._address, id), exposed

Here is the call graph for this function:

Here is the caller graph for this function:

Return some info about the servers shared objects and connections

Definition at line 581 of file managers.py.

00581 
00582     def _debug_info(self):
00583         '''
00584         Return some info about the servers shared objects and connections
00585         '''
00586         conn = self._Client(self._address, authkey=self._authkey)
00587         try:
00588             return dispatch(conn, None, 'debug_info')
00589         finally:
00590             conn.close()

Here is the call graph for this function:

def multiprocessing.managers.BaseManager._finalize_manager (   process,
  address,
  authkey,
  state,
  _Client 
) [static, private]
Shutdown the manager process; will be registered as a finalizer

Definition at line 608 of file managers.py.

00608 
00609     def _finalize_manager(process, address, authkey, state, _Client):
00610         '''
00611         Shutdown the manager process; will be registered as a finalizer
00612         '''
00613         if process.is_alive():
00614             util.info('sending shutdown message to manager')
00615             try:
00616                 conn = _Client(address, authkey=authkey)
00617                 try:
00618                     dispatch(conn, None, 'shutdown')
00619                 finally:
00620                     conn.close()
00621             except Exception:
00622                 pass
00623 
00624             process.join(timeout=0.2)
00625             if process.is_alive():
00626                 util.info('manager still alive')
00627                 if hasattr(process, 'terminate'):
00628                     util.info('trying to `terminate()` manager process')
00629                     process.terminate()
00630                     process.join(timeout=0.1)
00631                     if process.is_alive():
00632                         util.info('manager still alive after terminate')
00633 
00634         state.value = State.SHUTDOWN
00635         try:
00636             del BaseProxy._address_to_local[address]
00637         except KeyError:
00638             pass

Here is the call graph for this function:

Return the number of shared objects

Definition at line 591 of file managers.py.

00591 
00592     def _number_of_objects(self):
00593         '''
00594         Return the number of shared objects
00595         '''
00596         conn = self._Client(self._address, authkey=self._authkey)
00597         try:
00598             return dispatch(conn, None, 'number_of_objects')
00599         finally:
00600             conn.close()

Here is the call graph for this function:

def multiprocessing.managers.BaseManager._run_server (   cls,
  registry,
  address,
  authkey,
  serializer,
  writer,
  initializer = None,
  initargs = () 
) [private]
Create a server, report its address and run it

Definition at line 545 of file managers.py.

00545 
00546                     initializer=None, initargs=()):
00547         '''
00548         Create a server, report its address and run it
00549         '''
00550         if initializer is not None:
00551             initializer(*initargs)
00552 
00553         # create server
00554         server = cls._Server(registry, address, authkey, serializer)
00555 
00556         # inform parent process of the server's address
00557         writer.send(server.address)
00558         writer.close()
00559 
00560         # run the manager
00561         util.info('manager serving at %r', server.address)
00562         server.serve_forever()

Here is the call graph for this function:

Connect manager object to the server process

Definition at line 498 of file managers.py.

00498 
00499     def connect(self):
00500         '''
00501         Connect manager object to the server process
00502         '''
00503         Listener, Client = listener_client[self._serializer]
00504         conn = Client(self._address, authkey=self._authkey)
00505         dispatch(conn, None, 'dummy')
00506         self._state.value = State.STARTED

Here is the call graph for this function:

Here is the caller graph for this function:

Return server object with serve_forever() method and address attribute

Definition at line 490 of file managers.py.

00490 
00491     def get_server(self):
00492         '''
00493         Return server object with serve_forever() method and address attribute
00494         '''
00495         assert self._state.value == State.INITIAL
00496         return Server(self._registry, self._address,
00497                       self._authkey, self._serializer)

def multiprocessing.managers.BaseManager.join (   self,
  timeout = None 
)
Join the manager process (if it has been spawned)

Definition at line 575 of file managers.py.

00575 
00576     def join(self, timeout=None):
00577         '''
00578         Join the manager process (if it has been spawned)
00579         '''
00580         self._process.join(timeout)

Here is the caller graph for this function:

def multiprocessing.managers.BaseManager.register (   cls,
  typeid,
  callable = None,
  proxytype = None,
  exposed = None,
  method_to_typeid = None,
  create_method = True 
)
Register a typeid with the manager type

Definition at line 643 of file managers.py.

00643 
00644                  method_to_typeid=None, create_method=True):
00645         '''
00646         Register a typeid with the manager type
00647         '''
00648         if '_registry' not in cls.__dict__:
00649             cls._registry = cls._registry.copy()
00650 
00651         if proxytype is None:
00652             proxytype = AutoProxy
00653 
00654         exposed = exposed or getattr(proxytype, '_exposed_', None)
00655 
00656         method_to_typeid = method_to_typeid or \
00657                            getattr(proxytype, '_method_to_typeid_', None)
00658 
00659         if method_to_typeid:
00660             for key, value in list(method_to_typeid.items()):
00661                 assert type(key) is str, '%r is not a string' % key
00662                 assert type(value) is str, '%r is not a string' % value
00663 
00664         cls._registry[typeid] = (
00665             callable, exposed, method_to_typeid, proxytype
00666             )
00667 
00668         if create_method:
00669             def temp(self, *args, **kwds):
00670                 util.debug('requesting creation of a shared %r object', typeid)
00671                 token, exp = self._create(typeid, *args, **kwds)
00672                 proxy = proxytype(
00673                     token, self._serializer, manager=self,
00674                     authkey=self._authkey, exposed=exp
00675                     )
00676                 conn = self._Client(token.address, authkey=self._authkey)
00677                 dispatch(conn, None, 'decref', (token.id,))
00678                 return proxy
00679             temp.__name__ = typeid
00680             setattr(cls, typeid, temp)
00681 
00682 #
00683 # Subclass of set which get cleared after a fork
00684 #

Here is the call graph for this function:

def multiprocessing.managers.BaseManager.start (   self,
  initializer = None,
  initargs = () 
)
Spawn a server process for this manager object

Definition at line 507 of file managers.py.

00507 
00508     def start(self, initializer=None, initargs=()):
00509         '''
00510         Spawn a server process for this manager object
00511         '''
00512         assert self._state.value == State.INITIAL
00513 
00514         if initializer is not None and not hasattr(initializer, '__call__'):
00515             raise TypeError('initializer must be a callable')
00516 
00517         # pipe over which we will retrieve address of server
00518         reader, writer = connection.Pipe(duplex=False)
00519 
00520         # spawn process which runs a server
00521         self._process = Process(
00522             target=type(self)._run_server,
00523             args=(self._registry, self._address, self._authkey,
00524                   self._serializer, writer, initializer, initargs),
00525             )
00526         ident = ':'.join(str(i) for i in self._process._identity)
00527         self._process.name = type(self).__name__  + '-' + ident
00528         self._process.start()
00529 
00530         # get address of server
00531         writer.close()
00532         self._address = reader.recv()
00533         reader.close()
00534 
00535         # register a finalizer
00536         self._state.value = State.STARTED
00537         self.shutdown = util.Finalize(
00538             self, type(self)._finalize_manager,
00539             args=(self._process, self._address, self._authkey,
00540                   self._state, self._Client),
00541             exitpriority=0
00542             )

Here is the caller graph for this function:


Member Data Documentation

Definition at line 479 of file managers.py.

Definition at line 480 of file managers.py.

Definition at line 484 of file managers.py.

Definition at line 520 of file managers.py.

Definition at line 473 of file managers.py.

Definition at line 483 of file managers.py.

Definition at line 474 of file managers.py.

Definition at line 481 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.

Definition at line 536 of file managers.py.


Property Documentation

multiprocessing.managers.BaseManager.address = property(lambda self: self._address) [static]

Definition at line 639 of file managers.py.


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