should avoid __del__ in non-debug mode
Bug #791612 reported by
Martin Pool
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Bazaar |
Fix Released
|
Medium
|
Martin Pool |
Bug Description
Having a __del__ method on an object can impair Python gc performance, even if the del method does nothing interesting.
bzr's coding conventions generally ban del methods that have external effects, such as closing a file, because there is no guarantee they will be called at the right time. However we do currently have some that just warn the developer the object was not closed.
We could instead only install those methods when eg -Dleaked is set, so that in the normal case they won't interfere with gc.
Related branches
lp:~mbp/bzr/rm-del-methods
- John A Meinel: Needs Information
- Bazaar Developers: Pending requested
- Andrew Bennetts: Pending requested
-
Diff: 258 lines (+33/-78)7 files modifiedbzrlib/atomicfile.py (+0/-4)
bzrlib/lock.py (+0/-6)
bzrlib/lockable_files.py (+17/-46)
bzrlib/tests/test_fifo_cache.py (+5/-5)
bzrlib/transport/memory.py (+0/-6)
bzrlib/transport/sftp.py (+0/-6)
doc/developers/code-style.txt (+11/-5)
tags: | added: debug memory tech-debt |
Changed in bzr: | |
assignee: | nobody → Martin Pool (mbp) |
status: | Confirmed → In Progress |
To post a comment you must log in.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 6/2/2011 1:35 AM, Martin Pool wrote:
> Public bug reported:
>
> Having a __del__ method on an object can impair Python gc performance,
> even if the del method does nothing interesting.
>
> bzr's coding conventions generally ban del methods that have external
> effects, such as closing a file, because there is no guarantee they will
> be called at the right time. However we do currently have some that
> just warn the developer the object was not closed.
>
> We could instead only install those methods when eg -Dleaked is set, so
> that in the normal case they won't interfere with gc.
>
> ** Affects: bzr
> Importance: Medium
> Status: Confirmed
>
>
> ** Tags: debug memory tech-debt
>
> ** Tags added: debug memory tech-debt
>
If you are saying "non-debug" mode you could also do:
if __debug__:
def __del__(self):
...
However, those objects were intentionally crafted to hang off the end of
a cycle, rather than participate in it. I thought we were pretty careful
with it. (Common state was factor out, and is only accessed through the
object with __del__, etc.)
John
=:->
-----BEGIN PGP SIGNATURE----- enigmail. mozdev. org/
s5xUACgkQJdeBCY SNAAMIBwCcCn+ 0eU6VcsmoM/ xCvRmxGYV3 ygu1AgJ6Seywmw7 FQ
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://
iEYEARECAAYFAk3
OIIAoM9CMG6Y2Qb
=rT23
-----END PGP SIGNATURE-----