From 7de2fd83706ce376caa95b235069da6fd2417960 Mon Sep 17 00:00:00 2001 From: Irony <892768447@qq.com> Date: Fri, 28 Dec 2018 14:48:26 +0800 Subject: [PATCH] QThread --- .settings/org.eclipse.core.resources.prefs | 8 ++--- .../继承QThread.py => QThread/InheritQThread.py | 2 +- QThread/README.en.md | 0 QThread/README.md | 33 ++++++++++++++++++ QThread/ScreenShot/InheritQThread.png | Bin 0 -> 1857 bytes .../ScreenShot/SuspendThread.gif | Bin .../ScreenShot/WakeupThread.gif | Bin .../线程挂起恢复.py => QThread/SuspendThread.py | 0 .../线程休眠唤醒.py => QThread/WakeupThread.py | 0 {多线程 => QThread}/moveToThread.py | 0 多线程/README.md | 25 ------------- 11 files changed, 38 insertions(+), 30 deletions(-) rename 多线程/继承QThread.py => QThread/InheritQThread.py (98%) create mode 100644 QThread/README.en.md create mode 100644 QThread/README.md create mode 100644 QThread/ScreenShot/InheritQThread.png rename 多线程/ScreenShot/线程挂起恢复.gif => QThread/ScreenShot/SuspendThread.gif (100%) rename 多线程/ScreenShot/线程休眠唤醒.gif => QThread/ScreenShot/WakeupThread.gif (100%) rename 多线程/线程挂起恢复.py => QThread/SuspendThread.py (100%) rename 多线程/线程休眠唤醒.py => QThread/WakeupThread.py (100%) rename {多线程 => QThread}/moveToThread.py (100%) delete mode 100644 多线程/README.md diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 5f7f528..136d4bf 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -8,6 +8,10 @@ encoding//QTableView/CopyContent/CopyContent.py=utf-8 encoding//QTableView/CopyContent/__main__.py=utf-8 encoding//QTableWidget/SqlQuery/SqlQuery.py=utf-8 encoding//QTableWidget/SqlQuery/__main__.py=utf-8 +encoding//QThread/moveToThread.py=utf-8 +encoding//QThread/\u7EBF\u7A0B\u4F11\u7720\u5524\u9192.py=utf-8 +encoding//QThread/\u7EBF\u7A0B\u6302\u8D77\u6062\u590D.py=utf-8 +encoding//QThread/\u7EE7\u627FQThread.py=utf-8 encoding//QTreeWidget/ParsingJson.py=utf-8 encoding//\u5176\u5B83/C\u548CC++\u6269\u5C55/py\u8F6Cpyd/pydmod.py=utf-8 encoding//\u5176\u5B83/QRC\u8D44\u6E90\u6587\u4EF6\u4F7F\u7528/qrctest1.py=utf-8 @@ -56,10 +60,6 @@ encoding//\u56FE\u7247/\u663E\u793A.9\u683C\u5F0F\u56FE\u7247/\u7EAFpython\u7248 encoding//\u56FE\u7247/\u663E\u793A.9\u683C\u5F0F\u56FE\u7247/\u7EAFpython\u7248\u672C1/testNinePatch.py=utf-8 encoding//\u56FE\u7247/\u663E\u793A.9\u683C\u5F0F\u56FE\u7247/\u7EAFpython\u7248\u672C2/QtNinePatch.py=utf-8 encoding//\u56FE\u7247/\u663E\u793A.9\u683C\u5F0F\u56FE\u7247/\u7EAFpython\u7248\u672C2/testQtNinePatch.py=utf-8 -encoding//\u591A\u7EBF\u7A0B/moveToThread.py=utf-8 -encoding//\u591A\u7EBF\u7A0B/\u7EBF\u7A0B\u4F11\u7720\u5524\u9192.py=utf-8 -encoding//\u591A\u7EBF\u7A0B/\u7EBF\u7A0B\u6302\u8D77\u6062\u590D.py=utf-8 -encoding//\u591A\u7EBF\u7A0B/\u7EE7\u627FQThread.py=utf-8 encoding//\u591A\u9875\u9762/QScrollArea/\u4EFFQQ\u8BBE\u7F6E\u9762\u677F/SettingUi.py=utf-8 encoding//\u591A\u9875\u9762/QScrollArea/\u4EFFQQ\u8BBE\u7F6E\u9762\u677F/\u4EFFQQ\u8BBE\u7F6E\u9762\u677F.py=utf-8 encoding//\u591A\u9875\u9762/QStackedWidget/\u5DE6\u4FA7\u9009\u9879\u5361/\u5DE6\u4FA7\u9009\u9879\u5361.py=utf-8 diff --git a/多线程/继承QThread.py b/QThread/InheritQThread.py similarity index 98% rename from 多线程/继承QThread.py rename to QThread/InheritQThread.py index a1c8804..ed49605 100644 --- a/多线程/继承QThread.py +++ b/QThread/InheritQThread.py @@ -6,7 +6,7 @@ Created on 2018年3月9日 @author: Irony @site: https://pyqt5.com, https://github.com/892768447 @email: 892768447@qq.com -@file: inheritQThread +@file: InheritQThread @description: 继承QThread """ from PyQt5.QtCore import QThread, pyqtSignal diff --git a/QThread/README.en.md b/QThread/README.en.md new file mode 100644 index 0000000..e69de29 diff --git a/QThread/README.md b/QThread/README.md new file mode 100644 index 0000000..6f52c7c --- /dev/null +++ b/QThread/README.md @@ -0,0 +1,33 @@ +# QThread + +PyQt多线程的简单使用例子 + +## 1、继承QThread +[运行 InheritQThread.py](InheritQThread.py) + +![InheritQThread](ScreenShot/InheritQThread.png) + +## 2、moveToThread +[运行 moveToThread.py](moveToThread.py) + +![moveToThread](ScreenShot/InheritQThread.png) + +## 3、线程挂起恢复 +[运行 SuspendThread.py](SuspendThread.py) + +注意,这里只是简单演示,在应用这些代码时要小心 + +1. 这里使用windows的api实现,主要用到`SuspendThread`和`ResumeThread`函数 +1. 利用`ctypes.windll.kernel32.OpenThread(win32con.PROCESS_ALL_ACCESS, False, int(QThread.currentThreadId()))` +1. 得到线程的句柄,然后就可以通过上面的两个函数对其进行挂起与恢复 + +`ctypes.windll.kernel32.TerminateThread`终止线程,不推荐 + +![SuspendThread](ScreenShot/SuspendThread.gif) + +## 4、线程休眠唤醒 +[运行 WakeupThread.py](WakeupThread.py) + +使用 `QWaitCondition` 的 `wait` 和 `wakeAll` 方法 + +![WakeupThread](ScreenShot/WakeupThread.gif) \ No newline at end of file diff --git a/QThread/ScreenShot/InheritQThread.png b/QThread/ScreenShot/InheritQThread.png new file mode 100644 index 0000000000000000000000000000000000000000..e1979c09f147ba065143faf03ffaac35d8a7c449 GIT binary patch literal 1857 zcmZ8idpHvc8()ZRE+JAQOgrwJ<2GR~6WL-&M7c$za-vvrCtprwV#b!8Hbmzf5^^8$ zks~u>)7LFaeb2UIr{n0G0Tq8^nF? zJ)?Mo)8U9I!ek4$Z=abSQOEpTQ)1bRyOq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