def __init__(self, token, manager=None, authkey=None, exposed=None, incref=True): BaseProxy._mutex.acquire() try: tls_idset = BaseProxy._address_to_local.get(token.address, None) if tls_idset is None: tls_idset = ThreadLocalStorage(), ProcessLocalSet() BaseProxy._address_to_local[token.address] = tls_idset finally: BaseProxy._mutex.release() # self._tls is used to record the connection used by this # thread to communicate with the manager at token.address self._tls = tls_idset[0] # self._idset is used to record the identities of all shared # objects for which the current process owns references and # which are in the manager at token.address self._idset = tls_idset[1] self._token = token self._id = self._token.id self._manager = manager if authkey: self._authkey = authkey elif self._manager: self._authkey = self._manager else: self._authkey = currentProcess().getAuthKey() if incref: self._incref() _registerAfterFork(self, BaseProxy._afterFork)
def _connect(self): debug('making connection to manager') name = currentProcess().getName() if threading.currentThread().getName() != 'MainThread': name += '|' + threading.currentThread().getName() connection = Client(self._token.address, authkey=self._authkey) dispatch(connection, None, 'acceptConnection', (name, )) self._tls.connection = connection
def _connect(self): debug('making connection to manager') name = currentProcess().getName() if threading.currentThread().getName() != 'MainThread': name += '|' + threading.currentThread().getName() connection = Client(self._token.address, authkey=self._authkey) dispatch(connection, None, 'acceptConnection', (name,)) self._tls.connection = connection
def RebuildProxy(func, token, kwds={}): ''' Function used for unpickling proxy objects. If possible the shared object is returned, or otherwise a proxy for it. ''' server = getattr(currentProcess(), '_server', None) if server and server.address == token.address: return server.id_to_obj[token.id][0] else: incref = ( kwds.pop('incref', True) and not getattr(currentProcess(), '_inheriting', False) ) try: return func(token, manager=None, authkey=None, incref=incref, **kwds) except AuthenticationError: raise AuthenticationError, 'cannot rebuild proxy without authkey'
def serveForever(self, verbose=True): ''' Start server in the current process ''' assert not self._started self._started = True registry, _ = BaseManager._getRegistryCreators(self) server = Server(registry, self._address, self._authkey) currentProcess()._server = server if verbose: print >>sys.stderr, '%s serving at address %s' % \ (type(self).__name__, server.address) server.serveForever()
def _runServer(cls, registry, address, authkey, writer): ''' Create a server, report its address and run it ''' # create server server = Server(registry, address, authkey) currentProcess()._server = server # inform parent process of the server's address writer.send(server.address) writer.close() # run the manager info('manager serving at %r', server.address) server.serveForever()
def __repr__(self): try: if self._semlock._isMine(): name = currentProcess().getName() if threading.currentThread().getName() != 'MainThread': name += '|' + threading.currentThread().getName() elif self._semlock._getValue() == 1: name = 'None' elif self._semlock._count() > 0: name = 'SomeOtherThread' else: name = 'SomeOtherProcess' except (KeyboardInterrupt, SystemExit): raise except Exception: name = 'unknown' return '<Lock(owner=%s)>' % name
def __init__(self, address=None, authkey=None): ''' `address`: The address on which manager should listen for new connections. If `address` is None then an arbitrary one is chosen (which will be available as `self.address`). `authkey`: Only connections from clients which are using `authkey` as an authentication key will be accepted. If `authkey` is `None` then `currentProcess().getAuthKey()` is used. ''' self._address = address # XXX not necessarily the final address if authkey is None: self._authkey = authkey = currentProcess().getAuthKey() else: self._authkey = authkey assert type(authkey) is str self._started = False
def makeRecord(self, *args): record = self.__class__.makeRecord(self, *args) record.processName = process.currentProcess()._name return record