[Python-ideas] Automatic context managers

anatoly techtonik techtonik at gmail.com
Fri Apr 26 17:21:25 CEST 2013


On Fri, Apr 26, 2013 at 4:55 PM, Ethan Furman <ethan at stoneleaf.us> wrote:

> 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<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>
>>     <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.
>

Are you sure about that? The example on the PySide wiki is pretty
reproducible. With current garbage collector lazyness it should be at least
in some cases non-reliable.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130426/97258494/attachment.html>


More information about the Python-ideas mailing list