def monkeypatch_select(): log.debug("Monkeypatching STS select") mux_select = None demuxers = [] if self.multiplex_sockets: revert_select_monkeypatch() revert_socket_monkeypatch() # Monkey patch select to use our deterministic version mux_select = MultiplexedSelect() for c in self.controller_manager.controller_configs: # Connect the true sockets true_socket = connect_socket_with_backoff(address=c.address, port=c.port) true_socket.setblocking(0) io_worker = mux_select.create_worker_for_socket(true_socket) mux_select.set_true_io_worker(io_worker) demux = STSSocketDemultiplexer(io_worker, c.server_info) demuxers.append(demux) # Monkey patch select.select select._old_select = select.select select.select = mux_select.select # Monkey patch socket.socket socket._old_socket = socket.socket def socket_patch(protocol, sock_type): if sock_type == socket.SOCK_STREAM: return STSMockSocket(protocol, sock_type) else: socket._old_socket(protocol, sock_type) socket.socket = socket_patch return (mux_select, demuxers)
def monkeypatch_select(): log.debug("Monkeypatching STS select") mux_select = None demuxers = [] if self.multiplex_sockets: revert_select_monkeypatch() revert_socket_monkeypatch() # Monkey patch select to use our deterministic version mux_select = MultiplexedSelect() for c in self.controller_manager.controller_configs: # Connect the true sockets true_socket = connect_socket_with_backoff( address=c.address, port=c.port) true_socket.setblocking(0) io_worker = mux_select.create_worker_for_socket( true_socket) mux_select.set_true_io_worker(io_worker) demux = STSSocketDemultiplexer(io_worker, c.server_info) demuxers.append(demux) # Monkey patch select.select select._old_select = select.select select.select = mux_select.select # Monkey patch socket.socket socket._old_socket = socket.socket def socket_patch(protocol, sock_type): if sock_type == socket.SOCK_STREAM: return STSMockSocket(protocol, sock_type) else: socket._old_socket(protocol, sock_type) socket.socket = socket_patch return (mux_select, demuxers)
def monkeypatch_select(multiplex_sockets, controller_manager): mux_select = None demuxers = [] if multiplex_sockets: log.debug("Monkeypatching STS select") revert_select_monkeypatch() # Monkey patch select to use our deterministic version mux_select = MultiplexedSelect() for c in controller_manager.controller_configs: # Connect the true sockets true_socket = connect_socket_with_backoff(address=c.address, port=c.port) true_socket.setblocking(0) io_worker = mux_select.create_worker_for_socket(true_socket) demux = STSSocketDemultiplexer(io_worker, c.server_info) demuxers.append(demux) # Monkey patch select.select select._old_select = select.select select.select = mux_select.select return (mux_select, demuxers)