This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: tkFont may reuse font names
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: asvetlov Nosy List: BreamoreBoy, asvetlov, effbot, gpolo, lpd, python-dev
Priority: low Keywords: patch

Created on 2003-09-08 07:52 by effbot, last changed 2022-04-10 16:11 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tkfont_bug.py effbot, 2003-09-08 07:52
nonamerepeat.diff gpolo, 2009-06-21 20:49 review
Messages (7)
msg18102 - (view) Author: Fredrik Lundh (effbot) * (Python committer) Date: 2003-09-08 07:52
(sent to me instead of to the bug manager; note that 
the tkFont naming approach is also used for widgets and 
callbacks /F)

The class tkFont has a problem name it chooses if no 
name is
given. The choosen method 'name = "font" + str(id
(self))' isn't safe
because the name may exists longer than the Font 
object and so another
Font object may be created with a different font but the 
same
id() and so the same name. id() says

    Return the identity of an object.  This is guaranteed 
to be unique
    among simultaneously existing objects.
          ^^^^^^^^^^^^^^^^^^^^^^^

Note that this bug doesn't strike if you hold a reference 
to the Font
object and so the GC can't reclaim the space.

To reproduce run the attached program. It produces 
something like:

previously: ('Times', 15, 'bold')
now: ('Times', 18, 'bold')
iterations: 8
mapping: {'font136494612': ('Times', 
14, 'bold'), 'font136499772': ('Times', 
15, 'bold'), 'font136545468': ('Times', 
17, 'bold'), 'font136483156': ('Times', 
11, 'bold'), 'font136502700': ('Times', 
12, 'bold'), 'font136510460': ('Times', 
13, 'bold'), 'font136515228': ('Times', 
16, 'bold'), 'font136365348': ('Times', 10, 'bold')}
Traceback (most recent call last):
  File "tkfont_bug.py", line 20, in ?
    assert 0
AssertionError

Raimar
msg18103 - (view) Author: L. Peter Deutsch (lpd) Date: 2007-06-03 05:16
This bug has bitten me too, in a real program.
msg64948 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-04-04 20:17
This still happens, but around 2000 iterations here on newer Python
versions (trunk, 3alpha, 2.5.x, 2.4.x). Using Python 1.6 I've got it at
2 iterations (min), but.. is this going to be fixed or given the amount
of iterations needed nowadays this is no longer a problem ? If it should
be fixed, are there any suggestions on how to proceed ?
msg89581 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2009-06-21 20:49
Uhm, now I'm getting it at around 3 iterations with python-trunk. So,
can't we just use a simple generator for this ? Patch attached.

The same could be done for widget and callback naming.
msg114268 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-08-18 19:26
Patch is really simple and looks ok to me, can we get this committed please.
msg157394 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-04-03 06:48
New changeset a77e23135675 by Andrew Svetlov in branch 'default':
Issue #802310: Generate always unique tkinter font names if not directly passed
http://hg.python.org/cpython/rev/a77e23135675
msg157395 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-04-03 06:51
I've pushed fix inspired by Guilherme's suggestion.

Fix has been applied to 3.3 only because:
1. It changes font name generation schema
2. It's definitelly minor issue as exists starting from 2003.

Thanks.
History
Date User Action Args
2022-04-10 16:11:04adminsetgithub: 39201
2012-04-03 06:51:05asvetlovsetstatus: open -> closed
versions: - Python 2.7, Python 3.2
messages: + msg157395

resolution: fixed
stage: patch review -> resolved
2012-04-03 06:48:13python-devsetnosy: + python-dev
messages: + msg157394
2012-04-03 05:42:28asvetlovsetassignee: asvetlov
2012-03-21 17:27:30asvetlovsetnosy: + asvetlov

versions: + Python 3.3, - Python 3.1
2010-08-18 19:26:28BreamoreBoysetversions: + Python 3.1, Python 2.7, Python 3.2
nosy: + BreamoreBoy

messages: + msg114268

type: behavior
stage: patch review
2009-06-21 20:49:11gpolosetfiles: + nonamerepeat.diff
keywords: + patch
messages: + msg89581
2008-04-04 20:17:01gpolosetnosy: + gpolo
messages: + msg64948
2003-09-08 07:52:56effbotcreate