PyQt, Widgets, and Threading. Simple example of incorrect GUI update?
-
Hello community,
I want to demonstrate students PyQt (I use PyQt5 on Windows) GUI Widgets Application and Threading with samples as simple as possible. I have one sample to show a blocking app without threading, to motivate the use of threading in the first place. And I have another sample showing the correct useage of PyQt Widges and QThreads and signals and slots.
What I am looking for is a sample for incorrect GUI update, directly from a worker thread. I tried hard, but I couldn't get any exceptions or even noticable effects. The GUI still updates more or less correctly. Maybe someone has a sample or could think of a Widget that is more sensitive to thread updates. QLabel, and QListWidget just seem to be too robust to show real problems.
So any ideas on provoking this? Hope my question is understandable.Best regards
Johannes -
Hi,
While it's a pretty goal to show why it's wrong to update widgets from a different thread, you might have issue reproducing this at will. This is in the zone of undefined behaviour and depends highly on the OS beside what you are modifying and it might just work for a while, do something funky or crash the application.
Also, there might also be the architecture of Python itself that could be at play since it's currently not a true multithreaded language if you take the GIL into account.