0

I'm making a stock trading app where I'm using matplotlib to create an graph that updates in real time in an event loop like so:

            fig = plt.figure()
            ani = animation.FuncAnimation(fig, animate, interval=2000)
            plt.show()
            loop.call_later(7100, renew_token)

However, I also want to run a function (renew_token) every x seconds that checks to see if the user has been logged out.


        def renew_token():
            response = self.session.get(url, header_auth=True)
            print(response)
            loop.call_later(5000, renew_token)

If I create an event loop and run the graph function, the rest of the code doesn't execute until the graph window is closed. How could I run my code in parallel with the graph updating?

mvgxx
  • 1
  • Would replacing plt.show() by plt.show(block=False) + plt.pause(0.001) solve your issue? https://stackoverflow.com/questions/65951965/when-i-plot-something-in-python-the-programs-execution-stops-until-i-close-the-p/65952056#65952056 – Christian Karcher Sep 09 '22 at 05:08

0 Answers0