I don't seem to find the right solution to this error. The program keep giving "RuntimeError: no running event loop". 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.