QRunnableclass is an interface for representing a task or piece of code that needs to be executed, represented by your reimplementation of therun()函数。可以使用
QThreadPoolto execute your code in a separate thread.QThreadPooldeletes theQRunnableautomatically ifautoDelete()返回true(the default). UsesetAutoDelete()to change the auto-deletion flag.
QThreadPoolsupports executing the sameQRunnable多次通过调用tryStart(this) from within therun()function. IfautoDeleteis enabled theQRunnable将被删除当最后一个线程退出 run 函数时。调用start()multiple times with the sameQRunnablewhenautoDeleteis enabled creates a race condition and is not recommended.另请参阅
PySide2.QtCore.QRunnable.
autoDelete
(
)
¶
bool
返回
true
is auto-deletion is enabled; false otherwise.
If auto-deletion is enabled,
QThreadPool
will automatically delete this runnable after calling
run()
; otherwise, ownership remains with the application programmer.
PySide2.QtCore.QRunnable.
run
(
)
¶
Implement this pure virtual function in your subclass.
PySide2.QtCore.QRunnable.
setAutoDelete
(
_autoDelete
)
¶
_autoDelete
–
bool
Enables auto-deletion if
autoDelete
is true; otherwise auto-deletion is disabled.
If auto-deletion is enabled,
QThreadPool
will automatically delete this runnable after calling
run()
; otherwise, ownership remains with the application programmer.
Note that this flag must be set before calling
start()
. Calling this function after
start()
results in undefined behavior.
另请参阅