Last active
January 4, 2018 14:19
-
-
Save csaez/2e57f38eeb218dda3c4bdbb45f22cdf2 to your computer and use it in GitHub Desktop.
multiprocessing gui example
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 sys | |
import multiprocessing | |
from PyQt5 import QtWidgets | |
def calc(): | |
# random cpu bound computation | |
result = 0 | |
for i in range(10 ** 7): | |
result += i ** 2 | |
return result | |
if __name__ == "__main__": | |
app = QtWidgets.QApplication(sys.argv) | |
w = QtWidgets.QListWidget() | |
w.show() | |
# populate without blocking using all your cores! | |
pool = multiprocessing.Pool() | |
for _ in range(32): | |
pool.apply_async(calc, callback=lambda x: w.addItem(str(x))) | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment