python - NumPy/Scipy locks PyQt event loops -
i want call time-consuming scipy
functinons dedicated pyqt qthread. afaik, when calling scipy functions, release gil , qt event should work.
cannot tell me, how can cope it?
# -*- coding: utf-8 -*- import numpy np import scipy sp import scipy.interpolate import os import sys import time pyqt4 import qtcore, qtgui class longrunningworker(qtcore.qobject): result_ready = qtcore.pyqtsignal(tuple) @qtcore.pyqtslot() def generate_uber_mega_data(self): print "oy!" # time.sleep(5) r_ticks = np.linspace(0, 1000, 5000) phi_ticks = np.linspace(0, 2 * np.pi, 5000) r_grid, phi_grid = np.meshgrid(r_ticks, phi_ticks) print u"starting interpolation" spline = sp.interpolate.rectbivariatespline(r_ticks, phi_ticks, r_grid * phi_grid) print u"Интерполяция всё / interpolation complete" time.sleep(5) print "vey!" self.result_ready.emit((7, 40)) @qtcore.pyqtslot(tuple) def process_mega_data(mega_data): print mega_data if __name__ == "__main__": app = qtgui.qapplication(sys.argv) mega_button = qtgui.qpushbutton("press__________________________________________here") mega_button.show() background_thread = qtcore.qthread() worker = longrunningworker() worker.movetothread(background_thread) background_thread.start() # press here -- , interpolation start , gui events on spinbox freeze mega_button.clicked.connect(worker.generate_uber_mega_data) worker.result_ready.connect(process_mega_data) # little scum doesn't change values, when interpolation running! mega_spinbox = qtgui.qspinbox() mega_spinbox.show() sys.exit(app.exec_())
Comments
Post a Comment