Re: [Python-Dev] r88178 - python/branches/py3k/Lib/test/crashers/underlying_dict.py

2011-01-26 Thread Andreas Stührk
> I gets to a dict of class circumventing dictproxy. It's yet unclear
> why it segfaults.

The crash as well as the output "1" are both caused because updating
the class dictionary directly doesn't invalidate the method cache.
When the new value for "f" is assigned to the dict, the old "f" gets
garbage collected (because the method cache uses borrowed references),
but there is still an entry in the cache for the (now
garbage-collected) function. When "a.f" is executed next, the entry of
the cache is used and a new method is created. When that method gets
called, it returns "1" and when the interpreter tries to garbage
collect the new method on interpreter finalization, it segfaults
because the referenced "f" is already collected.

Regards,
Andreas
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Why does TemporaryDirectory not wait for `__enter__`?

2011-02-26 Thread Andreas Stührk
Hi

On Sat, Feb 26, 2011 at 12:52 PM, cool-RR  wrote:
> I noticed that the `TemporaryDirectory` context manager creates the folder
> on `__init__` rather than on `__enter__`, resulting in complexity, bugs, and
> hackarounds in `__del__`. I assume there's a good reason for this decision.
> What is it?

The reason is that you can use `TemporaryDirectory` without a context
manager too. Note that creating things in  `__init__` rather than in
`__enter__` isn't unusual -- it is done in the same way for regular
files. I'm not sure what you mean with "hackarounds in `__del__`", but
I assume you mean the code in `cleanup()`. That code tries to do the
right thing on interpreter shutdown when parts of the interpreter are
already gone and it emits a `ResourceWarning` if called implicitly
(IOW: when you didn't use `TemporaryDirectory` as a context manager
and didn't call its `cleanup()` method). So a bit of complexity is
there, but it really isn't about where the directory is created.

Regards,
Andreas
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com