I have found this code on the internet and modified it with RICH table-output: I have removed all the code that is not neccessary to understand (all the imports and so on). My PROBLEM is, that the Table repeats itself. But there is NO loop for building the table. Is it because of the asyncio ? Maybe I should use an other method of printing the table ?
[![enter image description here][1]][1]
table = Table(title="Unconfirmed Transactions", show_header=True)
table.add_column("Counter", justify="right", style="cyan")
#more columns added here
class ZMQHandler():
def __init__(self):
self.loop = asyncio.get_event_loop()
self.zmqContext = zmq.asyncio.Context()
self.zmqSubSocket = self.zmqContext.socket(zmq.SUB)
self.zmqSubSocket.setsockopt(zmq.RCVHWM, 0)
self.zmqSubSocket.setsockopt_string(zmq.SUBSCRIBE, "sequence")
self.zmqSubSocket.connect("tcp://127.0.0.1:%i" % port)
async def handle(self) :
#code stripped
table.add_row(str(counter), str(dataset[i][0]), str(a), str(b), amount_string, c)
asyncio.ensure_future(self.handle())
def start(self):
self.loop.add_signal_handler(signal.SIGINT, self.stop)
self.loop.create_task(self.handle())
self.loop.run_forever()
def stop(self):
self.loop.stop()
self.zmqContext.destroy()
daemon = ZMQHandler()
daemon.start()
[1]: https://i.stack.imgur.com/uAPVM.png