簡體   English   中英

Quamash QventLoop “RuntimeError: no running event loop” 在 python 和 PyQt5 錯誤

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

我似乎沒有找到解決此錯誤的正確方法。 該程序不斷給出“RuntimeError:沒有正在運行的事件循環”。 為什么事件循環沒有運行?

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

或者

from asyncqt import QEventLoop, QThreadExecutor

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM