[PyQt] Long running processes, threads, progress dialog

Hans-Peter Jansen hpj at urpla.net
Tue Mar 22 12:10:41 GMT 2011


On Tuesday 22 March 2011, 04:27:14 Catriona Johnson wrote:
> Hello
>
> I have a GUI application that occasionally has a number of long
> running processes - eg data deletions , html report generation.
>
> I have a custom progress widget that displays a spinning icon (my
> client didn't like the Qt QProgressDialog) which I display during
> long running processes - the user doesn't need to be able to interact
> with the GUI while this is happening.
>
> I have started to implement a worker thread to perform these long
> running processes. My question is do I initiate each process from the
> Thread's run method as follows or does each operation have its own
> thread ?? Do I need to use a secondary thread at all? Is there a
> better way ??
>
> def run(self):
> 		if self.operation == A_DELETE:
> 			self.completed = AModel.model().removeRecord(self.identity)
> 		elif self.operation == B_DELETE:
> 			self.completed = BModel.model().removeRecord(self.identity)
> 		elif self.operation == REPORTS:
> 			self.completed = ReportWriter.generateReport()
> 		self.stop()
> 		self.emit(SIGNAL("finished(bool)"), self.completed)
> 		self.wait()

You may want to read this article, which is mostly valid also for PyQt:

	http://www.linuxjournal.com/article/9602

From a PyQt POV and depending on where the action is, the presence of 
the GIL might want to be taken into account..

Pete


More information about the PyQt mailing list