[Tutor] pyqt __del__ race conditions in subclassed form
Alan Gauld
alan.gauld at btinternet.com
Mon Feb 29 20:12:19 EST 2016
On 29/02/16 16:22, CMG Thrissur wrote:
> This below given code is giving a race condition, i.e. sometimes gives
> the result as expected, sometimes gives error, sometimes just does
> nothing.
Don't use the __del__ method for that kind of code, put it in
the close event handler. You don't know when the del() will be
called or what state your dialog object and data will be in.
> def __del__(self):
> if self.Saved==False:
> choice = PyQt4.QtGui.QMessageBox.question(self,'Warning','Data modified. Do you want to save?',
> QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
> print(type(choice), choice)
> if choice == QMessageBox.Yes:
> self.SaveData()
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list