python - PyQt4, prevent app.exec_() from hanging the main thread -


i have simple code loads google.com pyqt4 library.
code:

import sys pyqt4.qtgui import qapplication pyqt4.qtcore import qurl pyqt4.qtwebkit import qwebview  class browser(qwebview):     def __init__(self):         qwebview.__init__(self)         self.loadfinished.connect(self._result_available)      def _result_available(self, ok):         frame = self.page().mainframe()         #print(frame.tohtml())         app.exit()  if __name__ == '__main__':     app = qapplication(sys.argv)     view = browser()     view.load(qurl('http://www.google.com'))     print('start')     app.exec_()#hangs main thread     print('end') 

my problem code app.exec_() hangs main thread while, between print start , print end.
there way scrape website in pyqt4 without making main thread hang while.
resume main thread's normal execution of code after app.exec_().

it's taking time download content web. app.exec_() runs application basically. if indeed hanging it's other factor influences proper execution of application. statements after app.exec_() executed once close application. app.exec_() called @ end of main (in c++ return app.exec_() can in pyqt of course).

when working content requires time downloaded , displayed in ui, have add multithreading in order allow main thread continue work (thus not creating called ui freeze) @ same time work in background. sole purpose of main thread keep track of ui , run it. else add main thread prevent ui working in fluent manner. have several options here - inheriting qthread (i wouldn't suggest doing scenario in particular), using qthread + qobject in order incorporate slots , signal in application (for example: page downloaded? -> if yes, signal ui display content), qrunnable etc.

so advice download content in separate thread , once it's done can add ui provide other form of visual feedback (this includes print statements :p).


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -