The ``BackgroundTaskThread`` class provides an all-in-one solution for executing a :py:class:`.BackgroundTask` in a thread. See the :py:class:`.BackgroundTask` for additional information. :param initial_progress_text: text description of the task to display in the status bar in the UI, defaul
| 1051 | |
| 1052 | |
| 1053 | class BackgroundTaskThread(BackgroundTask): |
| 1054 | """ |
| 1055 | The ``BackgroundTaskThread`` class provides an all-in-one solution for executing a :py:class:`.BackgroundTask` |
| 1056 | in a thread. |
| 1057 | |
| 1058 | See the :py:class:`.BackgroundTask` for additional information. |
| 1059 | |
| 1060 | :param initial_progress_text: text description of the task to display in the status bar in the UI, defaults to `""` |
| 1061 | :param can_cancel: whether to enable cancellation of the task, defaults to `False` |
| 1062 | """ |
| 1063 | def __init__(self, initial_progress_text: str = "", can_cancel: bool = False): |
| 1064 | class _Thread(threading.Thread): |
| 1065 | def __init__(self, task: 'BackgroundTaskThread'): |
| 1066 | threading.Thread.__init__(self) |
| 1067 | self.task = task |
| 1068 | |
| 1069 | def run(self): |
| 1070 | if self.task is None: |
| 1071 | raise Exception("Can not call run more than once per thread") |
| 1072 | try: |
| 1073 | self.task.run() |
| 1074 | finally: |
| 1075 | self.task.finish() |
| 1076 | self.task = None |
| 1077 | |
| 1078 | BackgroundTask.__init__(self, initial_progress_text, can_cancel) |
| 1079 | self.thread = _Thread(self) |
| 1080 | |
| 1081 | def run(self): |
| 1082 | pass |
| 1083 | |
| 1084 | def start(self): |
| 1085 | self.thread.start() |
| 1086 | |
| 1087 | def join(self, timeout=None): |
| 1088 | self.thread.join(timeout) |
nothing calls this directly
no outgoing calls
no test coverage detected