diff --git a/docs/source/release/v5.1.0/mantidworkbench.rst b/docs/source/release/v5.1.0/mantidworkbench.rst index 89e3ce05d8610020309c59c9174920abfd0110d0..0c558d2fe77725a4fcdb736f378b15ec25c95f29 100644 --- a/docs/source/release/v5.1.0/mantidworkbench.rst +++ b/docs/source/release/v5.1.0/mantidworkbench.rst @@ -13,6 +13,8 @@ Improvements - The plot selection dialog now correctly shows the full range of valid spectra to plot, not just the min to max range. - Tile plots are now reloaded correctly by project recovery. +- When you stop a script running in workbench it will now automatically attempt to cancel the algorithm the script is running, rather than wait for the current algorthm to end. + This is similar to what Mantidplot does, and should result in the script stopping much sooner. - Fixed an issue where some scripts were running slower if a plot was open at the same time. diff --git a/qt/python/mantidqt/utils/asynchronous.py b/qt/python/mantidqt/utils/asynchronous.py index bdaa790b1ad6c149f06fb878f0ba71efb8be7380..2b1dca15973c8779c200ab937cf4c0571183bb12 100644 --- a/qt/python/mantidqt/utils/asynchronous.py +++ b/qt/python/mantidqt/utils/asynchronous.py @@ -13,7 +13,7 @@ import sys import threading import time from traceback import extract_tb - +from mantid.api import IAlgorithm from enum import Enum @@ -83,6 +83,10 @@ class AsyncTask(threading.Thread): # https://stackoverflow.com/questions/5019436/python-how-to-terminate-a-blocking-thread ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(self.ident), ctypes.py_object(KeyboardInterrupt)) + #now try and cancel the running algorithm + alg = IAlgorithm._algorithmInThread(self.ident) + if alg is not None: + alg.cancel() time.sleep(0.1) @@ -147,6 +151,10 @@ class BlockingAsyncTaskWithCallback(AsyncTask): # https://stackoverflow.com/questions/5019436/python-how-to-terminate-a-blocking-thread ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(self.task.ident), ctypes.py_object(KeyboardInterrupt)) + #now try and cancel the running algorithm + alg = IAlgorithm._algorithmInThread(self.task.ident) + if alg is not None: + alg.cancel() time.sleep(0.1)