weakrefs and avoiding bad gc cycles

Aaron Bentley aaron at aaronbentley.com
Wed Jun 1 17:30:02 UTC 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 11-05-31 11:32 PM, Robert Collins wrote:
> That said, for some things even a fraction of a second will matter.
> One such case is when you have a file open in a directory that is
> going to be deleted - that file -must- be closed before the directory
> cleanup will fail on Windows. Other cases exist around threads and
> sockets. AFAIK all such cases have OS resources involved for them to
> matter.

Context managers are an excellent fit for this case.  They're quite
similar to Resource Acquisition Is Instantiation for Python.  Except
that it uses __enter__ / __exit__, not __init__ / __del__.  And new bzr
development can freely use them .

>  - So if you need to guarantee free/close/whatever before some other
> operation takes place then we have to manually arrange for that to
> take place.

Where "manually" can mean "by using a with statement".

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3mdxoACgkQ0F+nu1YWqI13wQCeObMMd6FwSNi6N6i3Qwh28EG8
pzsAn1qx0HHLy421ECUhbirOJZEzdpeZ
=aGq+
-----END PGP SIGNATURE-----



More information about the bazaar mailing list