简体   繁体   English

Quamash QventLoop “RuntimeError: no running event loop” 在 python 和 PyQt5 错误

[英]Quamash QventLoop “RuntimeError: no running event loop” error in python and PyQt5

I don't seem to find the right solution to this error.我似乎没有找到解决此错误的正确方法。 The program keep giving "RuntimeError: no running event loop".该程序不断给出“RuntimeError:没有正在运行的事件循环”。 Why is the event loop not running?为什么事件循环没有运行?

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()

This is one of the example online which am using to learn this concept.这是用于学习此概念的在线示例之一。 It seems to work for other students programmers but for me it gives me the error highlighted above.它似乎适用于其他学生程序员,但对我来说,它给了我上面突出显示的错误。

Quamash has not been active since July 2018, so it has numerous bugs that have not been solved, due to this inactivity, fork such as qasync ( python -m pip install qasync ) and asyncqt ( python -m pip install asyncqt ) have been created, so it recommends you to use one of those libraries, and for this it only changes to: Quamash has not been active since July 2018, so it has numerous bugs that have not been solved, due to this inactivity, fork such as qasync ( python -m pip install qasync ) and asyncqt ( python -m pip install asyncqt ) have been created ,因此它建议您使用其中一个库,为此它只更改为:

from qasync import QEventLoop, QThreadExecutor

OR或者

from asyncqt import QEventLoop, QThreadExecutor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM