Ejemplo n.º 1
0
def SocketClient(address):
    '''
    Return a connection object connected to the socket given by `address`
    '''
    family = address_type(address)
    with socket.socket(getattr(socket, family)) as s:
        s.setblocking(True)
        t = _init_timeout()

        while 1:
            try:
                s.connect(address)
            except socket.error as e:
                if e.args[0] != errno.ECONNREFUSED or _check_timeout(t):
                    debug('failed to connect to address %s', address)
                    raise
                time.sleep(0.01)
            else:
                break
        else:
            raise

        fd = duplicate(s.fileno())
    conn = _multiprocessing.Connection(fd)
    return conn
Ejemplo n.º 2
0
def reduce_handle(handle):
    if Popen.thread_is_spawning():
        return (None, Popen.duplicate_for_child(handle), True)
    dup_handle = duplicate(handle)
    _cache.add(dup_handle)
    sub_debug('reducing handle %d', handle)
    return (_get_listener().address, dup_handle, False)
Ejemplo n.º 3
0
 def accept(self):
     s, self._last_accepted = self._socket.accept()
     s.setblocking(True)
     fd = duplicate(s.fileno())
     conn = _multiprocessing.Connection(fd)
     s.close()
     return conn
Ejemplo n.º 4
0
def reduce_handle(handle):
    if Popen.thread_is_spawning():
        return (None, Popen.duplicate_for_child(handle), True)
    dup_handle = duplicate(handle)
    _cache.add(dup_handle)
    sub_debug('reducing handle %d', handle)
    return (_get_listener().address, dup_handle, False)
Ejemplo n.º 5
0
def SocketClient(address):
    '''
    Return a connection object connected to the socket given by `address`
    '''
    family = address_type(address)
    with socket.socket( getattr(socket, family) ) as s:
        s.setblocking(True)
        t = _init_timeout()

        while 1:
            try:
                s.connect(address)
            except socket.error as e:
                if e.args[0] != errno.ECONNREFUSED or _check_timeout(t):
                    debug('failed to connect to address %s', address)
                    raise
                time.sleep(0.01)
            else:
                break
        else:
            raise

        fd = duplicate(s.fileno())
    conn = _multiprocessing.Connection(fd)
    return conn
Ejemplo n.º 6
0
 def accept(self):
     s, self._last_accepted = self._socket.accept()
     s.setblocking(True)
     fd = duplicate(s.fileno())
     conn = _multiprocessing.Connection(fd)
     s.close()
     return conn
Ejemplo n.º 7
0
 def send_handle(conn, handle, destination_pid):
     process_handle = win32.OpenProcess(win32.PROCESS_ALL_ACCESS, False,
                                        destination_pid)
     try:
         new_handle = duplicate(handle, process_handle)
         conn.send(new_handle)
     finally:
         close(process_handle)
Ejemplo n.º 8
0
 def send_handle(conn, handle, destination_pid):
     process_handle = win32.OpenProcess(
         win32.PROCESS_ALL_ACCESS, False, destination_pid
         )
     try:
         new_handle = duplicate(handle, process_handle)
         conn.send(new_handle)
     finally:
         close(process_handle)
Ejemplo n.º 9
0
 def accept(self):
     while True:
         try:
             s, self._last_accepted = self._socket.accept()
         except socket.error as e:
             if e.args[0] != errno.EINTR:
                 raise
         else:
             break
     s.setblocking(True)
     fd = duplicate(s.fileno())
     conn = _multiprocessing.Connection(fd)
     s.close()
     return conn
Ejemplo n.º 10
0
 def accept(self):
     while True:
         try:
             s, self._last_accepted = self._socket.accept()
         except socket.error as e:
             if e.args[0] != errno.EINTR:
                 raise
         else:
             break
     s.setblocking(True)
     fd = duplicate(s.fileno())
     conn = _multiprocessing.Connection(fd)
     s.close()
     return conn
Ejemplo n.º 11
0
    t = _init_timeout()

    while 1:
        try:
            s.connect(address)
        except socket.error, e:
            if e.args[0] != errno.ECONNREFUSED or _check_timeout(t):
                debug('failed to connect to address %s', address)
                raise
            time.sleep(0.01)
        else:
            break
    else:
        raise

    fd = duplicate(s.fileno())
    conn = _multiprocessing.Connection(fd)
    s.close()
    return conn


#
# Definitions for connections based on named pipes
#

if sys.platform == 'win32':

    class PipeListener(object):
        '''
        Representation of a named pipe
        '''
Ejemplo n.º 12
0
    t = _init_timeout()

    while 1:
        try:
            s.connect(address)
        except socket.error, e:
            if e.args[0] != errno.ECONNREFUSED or _check_timeout(t):
                debug('failed to connect to address %s', address)
                raise
            time.sleep(0.01)
        else:
            break
    else:
        raise

    fd = duplicate(s.fileno())
    conn = _multiprocessing.Connection(fd)
    s.close()
    return conn

#
# Definitions for connections based on named pipes
#

if sys.platform == 'win32':

    class PipeListener(object):
        '''
        Representation of a named pipe
        '''
        def __init__(self, address, backlog=None):