GUI freezing while updating (result from QRunner)

Heads up! You've already completed this tutorial.

Jeremie | 2020-05-11 07:03:06 UTC | #1

Thanks for sharing this very informative tutorial.

https://www.pythonguis.com/courses/concurrent-execution/multithreading-pyqt-applications-qthreadpool/

I was wondering, what do you do when the GUI updating part is what makes the GUI freeze. For example if you add a time.sleep(0.8) in recurring_timer() then the GUI becomes unresponsive for 0.8 second. Which means you cannot click on the Danger button for that period of time for example (and you might think that you clicked the button but the click was never registered)

I am experiencing this issue right now as I am trying to make a live stock market GUI with 100s of prices updating live. In my case the main thread cannot cope with displaying all the prices (even throttled to only once a second) and still allow the user to type GUI inputs (like in a QLineEdit for example, or clicking some buttons). I have tried to run parallel threads to update the GUI but as many have pointed out on the internet this triggers random inexplicable crashes.

Any suggestions will be most welcome.

Thanks again


martin | 2020-05-11 07:03:57 UTC | #2

Hi Jeremie. glad you found the tutorial helpful!

Re: your question when doing anything that is on the main thread (and can potentially interrupt the GUI) it's important to remember to prefer doing things often, than doing them for a long time. It's fine to interrupt the GUI 100x per second, as long as those interrupts are short. When doing this Qt's own events will be interleaved with yours, and the delay will be imperceptible. Of course there is a point where the overhead of multiple events outweights the benefits, but this is higher than you might expect.

In your case I would try to either second the prices as individual "update" events, or batched at say 5 or so (experiment a bit). This should keep the delays below perceptible level, and allow you to update more often.

A more general point, when updating data "live" you almost always want some kind of (very short term) buffer than allows you to throw away data if you're not able to use it before the next data appears. You won't want to do this for graph plots, etc. but it can be helpful for simple numeric displays where out of data isn't shown.

Hope this helps!


Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak