Доброго времени суток. Мне необходимо выполнять 10 раз цикл в методе woriking, делаю программу на PyQt и при нажатии на кнопку получаю ошибку:
RuntimeWarning: coroutine 'Ui_MainWindow.working' was never awaited
sys.exit(app.exec_())
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
from datetime import datetime
from PyQt5 import QtCore, QtGui, QtWidgets
import asyncio
import requests
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(493, 267)
font = QtGui.QFont()
font.setFamily("WhitehallCyr")
font.setPointSize(12)
MainWindow.setFont(font)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
MainWindow.setInputMethodHints(QtCore.Qt.ImhNone)
MainWindow.setIconSize(QtCore.QSize(48, 48))
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.lblAPI = QtWidgets.QLabel(self.centralwidget)
self.lblAPI.setGeometry(QtCore.QRect(20, 14, 91, 21))
font = QtGui.QFont()
font.setFamily("Copperplate Cyrillic")
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
font.setStyleStrategy(QtGui.QFont.PreferDefault)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.pushButton.clicked.connect(self.working)
async def working(self):
for i in range(5):
try:
x = requests.get('https://w3schools.com')
print(x.status_code)
break
except:
self.lblResText_2.setText("Ошибка!")
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Строка 1"))
self.lblAP.setText(_translate("MainWindow", "Строка 2: "))
self.lblA.setText(_translate("MainWindow", "Строка 3: "))
self.lblS.setText(_translate("MainWindow", "Строка 4: "))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Подскажите пожалуйста, как сделать асинхронное выполнение цикла в количестве 10 раз ?