def get_open_port(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("", 0)) s.listen(1) port = s.getsockname()[1] s.close() return port
def get_ipc_socket(ipc_path, timeout=0.1): sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(ipc_path) sock.settimeout(timeout) yield sock sock.close()
def get_ipc_socket(ipc_path, timeout=0.1): if sys.platform == 'win32': # On Windows named pipe is used. Simulate socket with it. from web3.utils.windows import NamedPipe return NamedPipe(ipc_path) else: sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(ipc_path) sock.settimeout(timeout) return sock
def get_ipc_socket(ipc_path, timeout=0.1): if sys.platform == 'win32': # On Windows named pipe is used. Simulate socket with it. from web3.utils.windows import NamedPipe pipe = NamedPipe(ipc_path) with contextlib.closing(pipe): yield pipe else: sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(ipc_path) sock.settimeout(timeout) with contextlib.closing(sock): yield sock