Skip to content

Instantly share code, notes, and snippets.

@cr1901
Last active January 11, 2019 17:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cr1901/4f7c8aff20ba9d1b53a8 to your computer and use it in GitHub Desktop.
Save cr1901/4f7c8aff20ba9d1b53a8 to your computer and use it in GitHub Desktop.
quamash asyncio sample
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