Skip to content

Files

Latest commit

e3ad4ab · Mar 12, 2019

History

History

QThread

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Dec 28, 2018
Dec 28, 2018
Dec 28, 2018
Mar 12, 2019
Dec 28, 2018
Dec 28, 2018
Jan 5, 2019

QThread

1、继承QThread

运行 InheritQThread.py

InheritQThread

2、moveToThread

运行 moveToThread.py

moveToThread

3、线程挂起恢复

运行 SuspendThread.py

注意,这里只是简单演示,在应用这些代码时要小心

  1. 这里使用windows的api实现,主要用到SuspendThreadResumeThread函数
  2. 利用ctypes.windll.kernel32.OpenThread(win32con.PROCESS_ALL_ACCESS, False, int(QThread.currentThreadId()))
  3. 得到线程的句柄,然后就可以通过上面的两个函数对其进行挂起与恢复

ctypes.windll.kernel32.TerminateThread终止线程,不推荐

SuspendThread

4、线程休眠唤醒

运行 WakeupThread.py

使用 QWaitConditionwaitwakeAll 方法

WakeupThread