Python Forum
PyQt5 - Threading
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyQt5 - Threading
#4
To run in a separate thread you will need 1 function that will do all the work. It should grab all the values it needs, maybe disable the pushbutton, draw the progress bar and cancel button, perform all the work, erase the progress bar and cancel button, and enable the pushbutton. In the simplified example below this is the "thread_func". The "button_func" is the function that is called when the button is pressed.

Things may be as simple as:
def thread_func(a1, a2, a3):
    Disable pushbutton
    Draw progress bar and cancel button
    Call functions that do the work
    Erase the progress bar and cancel button
    Enable pushbutton

def button_func():
    x = threading.Thread(target=thread_func, args=(a1, 2, a3))  # Whatever args to pass
    x.start
The cancel button would set some flag that the processing code would monitor. You can kill a thread, but it is better to let the application exit gracefully. The worker code will also have to update the progress bar periodically.
Reply


Messages In This Thread
PyQt5 - Threading - by reginald - Apr-15-2020, 02:53 PM
RE: PyQt5 - Threading - by deanhystad - Apr-15-2020, 03:57 PM
RE: PyQt5 - Threading - by reginald - Apr-15-2020, 04:30 PM
RE: PyQt5 - Threading - by deanhystad - Apr-15-2020, 05:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 2,884 Apr-06-2019, 11:15 PM
Last Post: ZenWoR

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020