def test_local(self): top, bottom = LocalXport.create() top_th = threading.Thread(target=self.top_thread, args=(top,)) bottom_th = threading.Thread(target=self.bottom_thread, args=(bottom,)) top_th.start() bottom_th.start() top_th.join() bottom_th.join()
def setUpSlave(self): self.slave_xport, self.master_xport = LocalXport.create() slave_wire = Wire(self.slave_xport) slave_server = SlaveServer(slave_wire) self.slave_server_thd = threading.Thread(target=slave_server.serve) self.slave_server_thd.setDaemon(1) self.slave_server_thd.start() master_wire = Wire(self.master_xport) self.slave = RemoteSlave(master_wire)
def read_with_wire(self, writes): wire_xport, thread_xport = LocalXport.create() def thd(): for wr in writes: thread_xport.write(wr) thread_xport.close() self.thread = threading.Thread(target=thd) self.thread.setDaemon(1) self.thread.start() self.wire = Wire(wire_xport) return self.wire
def write_to_wire(self, boxes): result_xport, thread_xport = LocalXport.create() def thd(): wire = Wire(thread_xport) for box in boxes: wire.send_box(box) wire.close() thread = threading.Thread(target=thd) thread.setDaemon(1) thread.start() buf = '' while 1: d = result_xport.read() if not d: break buf += d thread.join() return buf