I have a visualizer for network traffic in Python. It uses Twisted for networking and calls run() it also has matplotlib for plotting and calls show(). Neither of these functions seem to return yet I need to call both of them to start the networking, then show the plot and ultimately update the plot as things happen on the network. Any solutions? Do I need threads?
I have a visualizer for network traffic in Python. It uses Twisted for networking
Share
matplotlib is a layer on top of some GUI toolkit. Which GUI toolkit depends a bit – on per-user configuration, on site-wide configuration, on the particulars of the matplotlib code you have.
Twisted has specific support for integrating with some GUI toolkits. So, for example, you can run matplotlib with its Gtk backend and use Twisted’s Gtk integration and then everything will play nicely together.
Here’s a 5 minute hack I threw together, based on what I know about integrating the various mainloops, and on a little bit of inspection of the matplotlib source code:
Notice:
mpl.py(hence themplimport up top)use('GTK')call before importingpyplotgtk2reactor.install()call before importingreactorpyplot.show()with a call to my ownShowsubclass with amainloopmethod starts the Gtk mainloop and the Twisted mainloop (both viareactor.run())This example seems to work fairly well. I haven’t explored this very much, so if there are problems that only crop up under more advanced usage, I don’t know about them.