Method to stop QThread that calls OpenCV functions

I have a simple PyQT application which, on press of a "calculate" button calls a long-running function that performs some image processing using OpenCV. To allow the GUI to remain responsive, the long-running function is executed in a QThread (I implemented this by following this excellent Real Python tutorial.

Ideally, I would like to be able to cancel the calculation (e.g. by pressing a "cancel" button). Given that the function is busy executing in OpenCV, is there a "nice"/safe way to do this? Or do we have to resort to a more brutal and risky method to kill the thread?

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum