Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
    def __init__(self, kind, value):
        sl = self._semlock = _processing.SemLock(kind, value)
        debug('created semlock with handle %s' % sl.handle)
        self.__setstate__((sl.handle, sl.kind, sl.maxvalue))

        if sys.platform != 'win32':
            def _afterFork(obj):
                obj._semlock._afterFork()
            _registerAfterFork(self, _afterFork)
Пример #4
0
    def __init__(self, maxsize=0):
        reader, writer = Pipe(duplex=False)
        rlock = Lock()
        if sys.platform == 'win32':
            wlock = None
        else:
            wlock = Lock()
        if maxsize < 0:
            maxsize = 0
        if maxsize == 0:
            sem = None
        else:
            sem = BoundedSemaphore(maxsize)

        state = maxsize, reader, writer, rlock, wlock, sem, os.getpid()
        self.__setstate__(state)

        if sys.platform != 'win32':
            _registerAfterFork(self, Queue._afterFork)
Пример #5
0
    def __init__(self, maxsize=0):
        reader, writer = Pipe(duplex=False)
        rlock = Lock()
        if sys.platform == 'win32':
            wlock = None
        else:
            wlock = Lock()
        if maxsize < 0:
            maxsize = 0
        if maxsize == 0:
            sem = None
        else:
            sem = BoundedSemaphore(maxsize)

        state = maxsize, reader, writer, rlock, wlock, sem, os.getpid()
        self.__setstate__(state)
        
        if sys.platform != 'win32':
            _registerAfterFork(self, Queue._afterFork)
Пример #6
0
#

_cache = set()


def _reset(obj):
    global _lock, _listener, _cache
    for h in _cache:
        closeHandle(h)
    _cache.clear()
    _lock = threading.Lock()
    _listener = None


_reset(None)
_registerAfterFork(_reset, _reset)


def _getListener():
    global _listener

    if _listener is None:
        _lock.acquire()
        try:
            if _listener is None:
                from processing.connection import Listener
                debug('starting listener and thread for sending handles')
                _listener = Listener(authenticate=True)
                t = threading.Thread(target=_serve)
                t.setDaemon(True)
                t.start()
Пример #7
0
 def __init__(self):
     _registerAfterFork(self, _clearNamespace)
Пример #8
0
 def __init__(self):
     _registerAfterFork(self, set.clear)
Пример #9
0
    # deprecated
    _callmethod = _callMethod
    _getvalue = _getValue


#
# Since BaseProxy._mutex might be locked at time of fork we reset it
#


def _resetMutex(obj):
    obj._mutex = threading.Lock()


_registerAfterFork(BaseProxy, _resetMutex)

#
# Function used for unpickling
#


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:
Пример #10
0
#
# Support for a per-process server thread which caches pickled handles
#

_cache = set()

def _reset(obj):
    global _lock, _listener, _cache
    for h in _cache:
        closeHandle(h)
    _cache.clear()
    _lock = threading.Lock()
    _listener = None

_reset(None)
_registerAfterFork(_reset, _reset)

def _getListener():
    global _listener

    if _listener is None:
        _lock.acquire()
        try:
            if _listener is None:
                from processing.connection import Listener
                debug('starting listener and thread for sending handles')
                _listener = Listener(authenticate=True)
                t = threading.Thread(target=_serve)
                t.setDaemon(True)
                t.start()
        finally:
Пример #11
0
 def __init__(self):
     _registerAfterFork(self, _clearNamespace)
Пример #12
0
 def __init__(self):
     _registerAfterFork(self, set.clear)
Пример #13
0
        except (SystemExit, KeyboardInterrupt):
            raise
        except Exception:
            return repr(self)[:-1] + "; '__str__()' failed>"

    # deprecated
    _callmethod = _callMethod
    _getvalue = _getValue

#
# Since BaseProxy._mutex might be locked at time of fork we reset it
#

def _resetMutex(obj):
    obj._mutex = threading.Lock()
_registerAfterFork(BaseProxy, _resetMutex)

#
# Function used for unpickling
#

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]