Quamash QventLoop "RuntimeError: no running event loop" error in python and PyQt5

Quamash QventLoop "RuntimeError: no running event loop" error in python and PyQt5

我似乎没有找到解决此错误的正确方法。该程序继续提供 "RuntimeError: no running event loop"。为什么事件循环不是运行?

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 月以来一直未激活,因此它有许多未解决的错误,由于这种不活动,已经创建了诸如 qasync(python -m pip install qasync) and asyncqt(python -m pip install asyncqt) 之类的分支,因此它建议您使用这些库之一,为此它只更改为:

from qasync import QEventLoop, QThreadExecutor

from asyncqt import QEventLoop, QThreadExecutor