-1

I have a GUI (tkinter) where i monitor data from a few sensors. The monitoring is realized as a realtime plot, which gets redrawn every 100 ms. The data from sensors is acquired via ethernet/ip connection. Therefore i use the get_attribute_single function from this package (https://github.com/rossmann-engineering/eeip.py). First i register a session with my network-communication unit (Keyence NU-EP1). Afterwards i can use the get_attribute-single to get the single data from each sensor. The script works perfect as expected, but the GUI is interactive only if i don't establish the ethernet_ip connection. If i use fake values (random.randint()) the gui and plot are working fine with an interactive GUI. If i use the ethernet/ip connection to acquire and plot real data, the GUI is getting very very slow. After clicking a button, it's color changes. But the color change is performed about a few seconds later, so really very slow. Any ideas how to solve this problem? Thanks in advance.

1 Answers1

0

Unless I'm missing something (I'm not familiar with tkinter) it sounds like you are doing everything in a single thread. That would create the described behavior since the GUI has to wait for the data to be fetched before it can update.
To solve this kind of issue you should look into concurrent programming, for example concurrent.futures.
Create a second thread that fetches the data and let the main thread handle the GUI.

Martin Riddar
  • 173
  • 4
  • 16
  • I am using multiprocessing. One process is acquiring the data, the mainloop is creating the GUI and refreshing the data/plot with the root.after() command, so the refreshing is not realized with a loop (that would cause the GUI to freeze completely). – RobertRondo Feb 14 '22 at 15:52
  • 1
    Have you tried benchmarking the application to see what's happening? Yappi can benchmark multithreaded apps. – Martin Riddar Feb 14 '22 at 20:10
  • i will try this, but it may take a few days as i am really busy atm – RobertRondo Feb 15 '22 at 15:12