0

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
  • i am not sure, but u seems to be creating task twice, first by `.create_task(..)` and 2nd by `.ensure_future(..)` – Abhi747 Dec 15 '22 at 11:44
  • this might be helpful https://stackoverflow.com/questions/36342899/asyncio-ensure-future-vs-baseeventloop-create-task-vs-simple-coroutine – Abhi747 Dec 15 '22 at 11:44
  • Thanks for the help. I've rewritten the whole asyncio functionality, but it doesn't change the messy output of the table. I think it's simply not possible to dynammically add rows onto a RICH table :( –  Dec 15 '22 at 14:47

0 Answers0