Thomas_Parker | 2020-10-01 09:50:08 UTC | #1
Heya,
I have a quick question. I used your workermanager 6 example to build it into my application.
However I notice if I click the top right X to close the application, the threads just carry on running regardless!
What is the best way to go about closing everything and cleaning up on app exit?
A point in the right direction greatly appreciated! Thanks
Thomas_Parker | 2020-10-01 11:28:24 UTC | #2
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!
I have just solved this with the following solution.
in my ui class (that inherites from a designer ui py file) I placed this function to catch the close event and issue a kill all to my worker managers (one set are providing a camera snapshot feed and the other is inference engines):
def closeEvent(self, event):
self.feed_workers.kill_all()
self.engine_workers.kill_all()
print('x button clicked')
event.accept()
I then had an issue of it bugging when closing. I found out I had to store the app in a variable and pass it to sys exit (I still dont fully understand why! but it works):
app.exec_() changed to:
app_ref = app.exec_()
sys.exit(app_ref)
Now when I click the top right X it kills the workers and exits error free.
PyQt6 Crash Course — a new tutorial in your Inbox every day
Beginner-focused crash course explaining the basics with hands-on examples.