def reduceHandle(handle): if thisThreadIsSpawning() and isInheritableHandle(handle): return (None, handle, True) dup_handle = duplicateHandle(handle) _cache.add(dup_handle) subDebug('reducing handle %d', handle) return (_getListener().address, dup_handle, False)
def _runFinalizers(minpriority=None): """ Run all finalizers whose exit priority is not None and at least minpriority Finalizers with highest priority are called first; finalizers with the same priority will be called in reverse order of creation. """ if minpriority is None: f = lambda p: p[0][0] is not None else: f = lambda p: p[0][0] is not None and p[0][0] >= minpriority items = sorted(filter(f, _registry.items()), reverse=True) for key, finalizer in items: subDebug("calling %s", finalizer) try: finalizer() except Exception: import traceback traceback.print_exc() if minpriority is None: _registry.clear()
def rebuildHandle(pickled_data): from processing.connection import Client address, handle, inherited = pickled_data if inherited: return handle subDebug('rebuilding handle %d', handle) conn = Client(address, authenticate=True) conn.send((handle, os.getpid())) new_handle = recvHandle(conn) conn.close() return new_handle
def __call__(self, wr=None): """ Run the callback unless it has already been called or cancelled Returns True if callback was run otherwise returns False """ try: del _registry[self._key] except KeyError: subDebug("finalizer no longer registered") else: subDebug("finalizer calling %s with args %s and kwargs %s", self._callback, self._args, self._kwargs) self._callback(*self._args, **self._kwargs) self._weakref = self._callback = self._args = self._kwargs = self._key = None return True
def __call__(self, wr=None): ''' Run the callback unless it has already been called or cancelled Returns True if callback was run otherwise returns False ''' try: del _registry[self._key] except KeyError: subDebug('finalizer no longer registered') else: subDebug('finalizer calling %s with args %s and kwargs %s', self._callback, self._args, self._kwargs) self._callback(*self._args, **self._kwargs) self._weakref = self._callback = self._args = \ self._kwargs = self._key = None return True
def __init__(self, address, backlog=None): self._address = address handle = win32.CreateNamedPipe( address, win32.PIPE_ACCESS_DUPLEX, win32.PIPE_TYPE_MESSAGE | win32.PIPE_READMODE_MESSAGE | win32.PIPE_WAIT, win32.PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE, win32.NMPWAIT_WAIT_FOREVER, win32.NULL ) self._handle_queue = [handle] self._last_accepted = None subDebug('listener created with address=%r', self._address) self.close = Finalize( self, PipeListener._finalize_pipelistener, args=(self._handle_queue, self._address), exitpriority=0 )
def __init__(self, address, family, backlog=1): self._socket = socket.socket(getattr(socket, family)) self._socket.bind(address) if family == 'AF_UNIX': os.chmod(address, int('0600', 8)) # readable/writable only by user self._socket.listen(backlog) address = self._socket.getsockname() if type(address) is tuple: address = (socket.getfqdn(address[0]),) + address[1:] self._address = address self._family = family self._last_accepted = None subDebug('listener bound to address %r', self._address) if family == 'AF_UNIX': self._unlink = Finalize( self, os.unlink, args=(self._address,), exitpriority=0 ) else: self._unlink = None
def _runFinalizers(minpriority=None): ''' Run all finalizers whose exit priority is not None and at least minpriority Finalizers with highest priority are called first; finalizers with the same priority will be called in reverse order of creation. ''' if minpriority is None: f = lambda p: p[0][0] is not None else: f = lambda p: p[0][0] is not None and p[0][0] >= minpriority items = sorted(filter(f, _registry.items()), reverse=True) for key, finalizer in items: subDebug('calling %s', finalizer) try: finalizer() except Exception: import traceback traceback.print_exc() if minpriority is None: _registry.clear()
def _finalize_pipelistener(queue, address): subDebug('closing listener with address=%r', address) for handle in queue: win32.CloseHandle(handle)