Last active
January 11, 2019 17:34
-
-
Save cr1901/4f7c8aff20ba9d1b53a8 to your computer and use it in GitHub Desktop.
quamash asyncio sample
This file contains 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
import asyncio | |
import atexit | |
from quamash import QEventLoop, QtGui, QtCore | |
from pyqtgraph import dockarea # Will import PyQt5.QtGui.QApplication | |
class MainWindow(QtGui.QMainWindow): | |
def __init__(self, app, server): | |
QtGui.QMainWindow.__init__(self) | |
self.exit_request = asyncio.Event() | |
def closeEvent(self, *args): | |
self.exit_request.set() | |
def save_state(self): | |
return bytes(self.saveGeometry()) | |
def restore_state(self, state): | |
self.restoreGeometry(QtCore.QByteArray(state)) | |
async def slow_operation(n): | |
await asyncio.sleep(1) | |
print("Slow operation {} complete".format(n)) | |
async def main(): | |
await asyncio.wait([ | |
slow_operation(1), | |
slow_operation(2), | |
slow_operation(3), | |
]) | |
app = QtGui.QApplication([]) | |
loop = QEventLoop(app) | |
asyncio.set_event_loop(loop) | |
atexit.register(loop.close) | |
#loop = asyncio.get_event_loop() | |
win = MainWindow(app, None) | |
win.show() | |
loop.run_until_complete(win.exit_request.wait()) | |
loop.run_until_complete(main()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment