-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy paththread.py
39 lines (28 loc) · 891 Bytes
/
thread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from typing import Any, List, Callable, Tuple
from PyQt5 import QtCore # type: ignore
class QtThread(QtCore.QThread):
"""
Wrapper around QThread
Parameters
----------
fun: Callable[..., Any]
Function that is called when ran
finished: QtCore.pyqtSignal
Signal emitted when callback is finished to return value to main thread
*args: List[Any]
Arguments that are passed into callback
"""
args: Tuple[Any, ...]
def __init__(self, fun, finished: QtCore.pyqtSignal, *args):
super(QtThread, self).__init__(None)
self.fun = fun
self._finished = finished
self.args = args
def run(self) -> None:
"""
Execute function and emit result
"""
result: Any = self.fun(*self.args)
self._finished.emit(result)
def __del__(self):
self.wait()