Quamash QventLoop“;RuntimeError:没有正在运行的事件循环;python和PyQt5中的错误
我似乎没有找到解决这个错误的正确方法。程序不断给出“RuntimeError:无运行事件循环”。为什么事件循环没有运行Quamash QventLoop“;RuntimeError:没有正在运行的事件循环;python和PyQt5中的错误,python,python-3.x,pyqt5,python-asyncio,qeventloop,Python,Python 3.x,Pyqt5,Python Asyncio,Qeventloop,我似乎没有找到解决这个错误的正确方法。程序不断给出“RuntimeError:无运行事件循环”。为什么事件循环没有运行 import sys import asyncio import time from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QProgressBar, QMessageBox from quamash import QEventLoop, QThreadExecutor class Quama
import sys
import asyncio
import time
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QProgressBar, QMessageBox
from quamash import QEventLoop, QThreadExecutor
class QuamashTrial(QWidget):
def __init__(self):
super(QuamashTrial, self).__init__()
self.initialize_widgets()
loop.run_until_complete(self.master())
QMessageBox.information(self, " ", 'It is done.')
def initialize_widgets(self):
vbox = QVBoxLayout()
self.progress = QProgressBar()
self.progress.setRange(0, 99)
self.progress.show()
self.setLayout(vbox)
@asyncio.coroutine
def master(self):
yield from self.first_50()
with QThreadExecutor(1) as exec:
yield from loop.run_in_executor(exec, self.last_50)
@asyncio.coroutine
def first_50(self):
for i in range(50):
self.progress.setValue(i)
yield from asyncio.sleep(.05)
def last_50(self):
for i in range(50,100):
loop.call_soon_threadsafe(self.progress.setValue, i)
time.sleep(.05)
if __name__ == "__main__":
app = QApplication(sys.argv)
loop = QEventLoop(app)
asyncio.set_event_loop(loop)
with loop:
q = QuamashTrial()
q.show()
loop.run_forever()
这是我用来学习这个概念的在线示例之一。它似乎适用于其他学生程序员,但对我来说,它给了我上面强调的错误。Quamash自2018年7月以来一直处于非活动状态,因此它有许多尚未解决的错误,由于这种不活动,例如(
python-m pip install qasync
)和(python-m pip install asyncqt
)已经创建,因此,它建议您使用这些库中的一个,为此,它只更改为:
从qasync导入QEventLoop,QThreadExecutor
或
从asyncqt导入QEventLoop,QThreadExecutor
现在,在我进行更改后,程序运行正常。