Skip to content

Instantly share code, notes, and snippets.

@csaez
Last active January 4, 2018 14:19
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 csaez/2e57f38eeb218dda3c4bdbb45f22cdf2 to your computer and use it in GitHub Desktop.
Save csaez/2e57f38eeb218dda3c4bdbb45f22cdf2 to your computer and use it in GitHub Desktop.
multiprocessing gui example
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