我在下面的(半)工作示例中有 4 个工作线程。我只能让前三个工作线程工作。如何让第四个线程运行?
print(QThread.idealThreadCount())在我的笔记本电脑上返回“8”。
我可以重新排序代码以使 3 个工作线程的任意组合运行。
from PyQt5.QtCore import QThread, QObject
from PyQt5.QtWidgets import QWidget
import sys
from PyQt5.QtWidgets import QApplication
import time
class A(QObject):
def run(self):
while 1:
print('A', time.ctime())
time.sleep(1)
class B(QObject):
def run(self):
while 1:
print('B', time.ctime())
time.sleep(1)
class C(QObject):
def run(self):
while 1:
print('C', time.ctime())
time.sleep(1)
class D(QObject):
def run(self):
while 1:
print('D', time.ctime())
time.sleep(1)
class window1(QWidget):
def __init__ (self, parent = None):
super().__init__ () #parent widget
print(QThread.idealThreadCount())
self.thread1 = QThread()
obj1 = A() …Run Code Online (Sandbox Code Playgroud)