python - Function offloaded to PyQt QThread is 2x slower -
i've been trying optimize application, , although made function run on average 10.06 seconds when profiled itself, when put on qthread
, takes around 17-22 seconds.
it's 2x slower in qthread
. how fix that?
the function initializing class called docxdocument
, document read word file , parsed needs.
i have qthread
creates class , uses qt signals send progress information gui. here code class:
class docximporterthread(qthread): ''' thread used import .docx document, report progress, , return document parsed. ''' reportprogress = pyqtsignal(int) reporterror = pyqtsignal(exception, str) reporttext = pyqtsignal(str) def __init__(self, filepath): qthread.__init__(self) self.setpriority(qthread.highestpriority) self._filepath = filepath self._docx = none self._html = '' self._bookmarks = none self._pages = none self._stop = false def run(self): def myprogresshook(percentage): self.reportprogress.emit(percentage) def mycancelhook(): return self._stop try: self._docx = docxdocument(self._filepath, myprogresshook, mycancelhook) if not self._stop: self._html = self._docx.getmainpage() self._bookmarks = self._docx.getheadings() self._pages = self._docx.getpages() except exception ex2: print 'error: .docx document didn\'t import.' self.reporterror.emit(ex2, traceback.format_exc())
the getmainpage()
, getheadings()
, , getpages()
instantaneous because return reference constructor created. here code used profile docxdocument
class:
testfile = 'some_file.docx' statsave = 'profile.out' def progress(percent): print ' --', percent, '--' cprofile.run('docxdocument(testfile)', filename=statsave) mystats = pstats.stats(statsave) mystats.sort_stats('cumulative', 'name') mystats.print_stats()
thanks time in looking @ this!
Comments
Post a Comment