Created
February 16, 2011 00:31
-
-
Save tmc/828606 to your computer and use it in GitHub Desktop.
pyqt gevent compat example
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
| diff --git a/session1/main.py b/session1/main.py | |
| index 93a204c..6508d12 100644 | |
| --- a/session1/main.py | |
| +++ b/session1/main.py | |
| @@ -3,6 +3,7 @@ | |
| """The user interface for our app""" | |
| import os,sys | |
| +import gevent | |
| # Import Qt modules | |
| from PyQt4 import QtCore,QtGui | |
| @@ -19,6 +20,18 @@ class Main(QtGui.QMainWindow): | |
| self.ui=Ui_MainWindow() | |
| self.ui.setupUi(self) | |
| +def mainloop(app): | |
| + while True: | |
| + app.processEvents() | |
| + while app.hasPendingEvents(): | |
| + app.processEvents() | |
| + gevent.sleep(0) | |
| + gevent.sleep(0) # don't appear to get here but cooperate again | |
| + | |
| +def testprint(): | |
| + print 'this is running' | |
| + gevent.spawn_later(1, testprint) | |
| + | |
| def main(): | |
| # Again, this is boilerplate, it's going to be the same on | |
| # almost every app you write | |
| @@ -26,7 +39,9 @@ def main(): | |
| window=Main() | |
| window.show() | |
| # It's exec_ because exec is a reserved word in Python | |
| - sys.exit(app.exec_()) | |
| + #sys.exit(app.exec_()) | |
| + gevent.joinall([gevent.spawn(testprint), gevent.spawn(mainloop, app)]) | |
| + print 'done' | |
| if __name__ == "__main__": |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment