Last active
July 20, 2022 10:29
-
-
Save internetimagery/0116ac4f1fed852b478420af7864df0e to your computer and use it in GitHub Desktop.
Super simple gevent qt loop polling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt5 import QtWidgets, QtCore | |
import gevent | |
def test(): | |
print("PRESSED") | |
for i in range(5): | |
gevent.sleep(1) | |
print("Waited", i) | |
print("Done") | |
class Main(QtWidgets.QMainWindow): | |
def __init__(self): | |
super(Main, self).__init__(None) | |
self._btn = QtWidgets.QPushButton("PRESS") | |
self._btn.clicked.connect(lambda: gevent.spawn(test)) | |
self.setCentralWidget(self._btn) | |
app = QtWidgets.QApplication([]) | |
win = Main() | |
win.show() | |
loop = QtCore.QTimer() | |
loop.setInterval(10) | |
loop.timeout.connect(lambda: gevent.sleep(0.01)) | |
loop.start() | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment