def SocketClient(address): ''' Return a connection object connected to the socket given by `address` ''' family = MP.address_type(address) s = socket.socket(getattr(socket, family)) defTimeOut = socket.getdefaulttimeout() s.settimeout(30) t = MP._init_timeout() while 1: try: s.connect(address) except socket.error as e: if e.args[0] != errno.ECONNREFUSED or MP._check_timeout(t): MP.debug('failed to connect to address %s', address) raise time.sleep(0.01) else: break else: raise s.settimeout(defTimeOut) fd = MP.duplicate(s.fileno()) conn = MP._multiprocessing.Connection(fd) s.close() return conn
def SocketClient(address, timeout=5): ''' Return a connection object connected to the socket given by `address` ''' family = address_type(address) s = socket.socket(getattr(socket, family)) if timeout: end_time = time.time() + timeout while 1: try: if timeout: cur_timeout = end_time - time.time() if cur_timeout <= 0: raise socket.timeout, "timed out." #s.settimeout(cur_timeout) s.connect(address) except socket.error, e: if e.args[0] != errno.ECONNREFUSED: # connection refused debug('failed to connect to address %s', address) raise time.sleep(0.01) else: break
def SocketClient(address): ''' Return a connection object connected to the socket given by `address` ''' family = MP.address_type(address) s = socket.socket(getattr(socket, family)) defTimeOut = socket.getdefaulttimeout() s.settimeout(30) t = MP._init_timeout() while 1: try: s.connect(address) except socket.error, e: if e.args[0] != errno.ECONNREFUSED or MP._check_timeout(t): MP.debug('failed to connect to address %s', address) raise time.sleep(0.01) else: break
def SocketClient(address): ''' Return a connection object connected to the socket given by `address` ''' family = MP.address_type(address) s = socket.socket( getattr(socket, family) ) defTimeOut = socket.getdefaulttimeout() s.settimeout(30) t = MP._init_timeout() while 1: try: s.connect(address) except socket.error, e: if e.args[0] != errno.ECONNREFUSED or MP._check_timeout(t): MP.debug('failed to connect to address %s', address) raise time.sleep(0.01) else: break
def SocketClientv6(address, authkey): ''' Return a connection object connected to the socket given by `address` ''' import _multiprocessing import errno import time from multiprocessing.connection import duplicate, _init_timeout from multiprocessing.connection import _check_timeout, debug s = socket.socket( socket.AF_INET6 ) 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