[Python-ideas] Automatic context managers
Ethan Furman
ethan at stoneleaf.us
Fri Apr 26 15:55:25 CEST 2013
On 04/26/2013 06:02 AM, anatoly techtonik wrote:
> On Thu, Apr 25, 2013 at 9:17 AM, Steven D'Aprano <steve at pearwood.info <mailto:steve at pearwood.info>> wrote:
>
> On 25/04/13 14:47, anatoly techtonik wrote:
>
> On Thu, Apr 25, 2013 at 7:23 AM, Cameron Simpson <cs at zip.com.au <mailto:cs at zip.com.au>> wrote:
>
>
> Then aren't you just talking about the __del__ method?
>
>
> No. The __del__ method is only called during garbage collection phase which
> may be delayed. In PySide the QObject is deleted immediately.
>
>
> Citation please. Where is this documented?
>
>
> Here:Â http://qt-project.org/wiki/PySide_Pitfalls
>
> """
> If a QObject falls out of scope in Python, it will get deleted. You have to take care of keeping a reference to the object:
>
> * Store it as an attribute of an object you keep around, e.g. self.window = QMainWindow()
> * Pass a parent QObject to the object’s constructor, so it gets owned by the parent
> """
>
> This thread on the PySide mailing list suggests that you are mistaken, PySide does not have superpowers over and
> above Python's garbage collector, and is subject to the exact same non-deterministic destructors as any other Python
> object. Whether you call that destructor __del__ or __exit__ makes no difference.
>
> http://www.mail-archive.com/__pyside@lists.openbossa.org/__msg01029.html
> <http://www.mail-archive.com/pyside@lists.openbossa.org/msg01029.html>
You'll notice it doesn't say "gets /immediately/ deleted" -- because it doesn't. It gets deleted when it gets garbage
collected.
--
~Ethan~
More information about the Python-ideas
mailing list