Sequential programming, threads, causality, and the nature of time

Dan wrote

I just started with PyQt and it seems pretty cool but tried to use a "progress bar" to track a long I/O process which introduced me to threads. I have things mostly working and understand how a long I/O would mess up the event queue for functions called AFTER the I/O process is called but I have experienced the following:

  1. FIRST I try & update some GUI widgets
  2. Immediately AFTERWARDS I call the long I/O function

Somehow step #2 interferes with step #1! It's like a time machine! ;-) I'm guessing that the call to step #1 just places GUI commands in a queue which immediately gets interfered with by step #2? So.... I guess all I'm asking for is a way to "flush the > queue" or somehow force step #1 to complete before step #2? I tried calling various "update" & "repaint" functions but that doesn't seem to help. I can (of course) deal with this via threads but it seems a bit inelegant... Any suggestions?


amohgyebigodwin10691

Qt always runs application logic before it runs UI code, even if Ui code was called first, that is what is going on.

To fix this call the I/O function in a separate thread.


PedanticHacker

Over 10,000 developers have bought Create GUI Applications with Python & Qt!
Create GUI Applications with Python & Qt6
Take a look

Downloadable ebook (PDF, ePub) & Complete Source code

Also available from Leanpub and Amazon Paperback

Hello Dan, welcome to the forum! 🙂

Martin has written a wonderful article about threads and thread-blocking in GUI applications. You'll find all your answers there.

Packaging Python Applications with PyInstaller by Martin Fitzpatrick — This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.

More info Get the book


Dan

Thanks! It really is an excellent article.

Create GUI Applications with Python & Qt5 by Martin Fitzpatrick — (PyQt5 Edition) The hands-on guide to making apps with Python — Over 10,000 copies sold!

More info Get the book


Mark As Complete
Martin Fitzpatrick

Sequential programming, threads, causality, and the nature of time was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt. Martin founded PythonGUIs to provide easy to follow GUI programming tutorials to the Python community. He has written a number of popular https://www.martinfitzpatrick.com/browse/books/ on the subject.