[Python-bugs-list] Reference counting problem? (PR#338)
gpk@bell-labs.com
gpk@bell-labs.com
Wed, 24 May 2000 10:24:33 -0400 (EDT)
Full_Name: Greg Kochanski
Version: 1.6 as of 5/21/2000
OS: Solaris 2.6
Submission from: h-135-104-33-130.research.bell-labs.com (135.104.33.130)
Python 1.6 seems to have some kind of reference counting problem.
The following function (in the midst of a large program)
will crash with a nonsensical exception if I comment out the
print statement.
def _pull_types(d, nc):
"""Finds all the column definitions in the data file,
that is, attributes in the form 'TTYPE#'. These
attributes tell you what kind of data is in a specific
column. It then builds an output dictionary that
tells you what column contains any desired type of data."""
ts = type('')
kl = d.keys()
o = {}
for k in kl:
assert type(k)==ts, 'Key must be string'
# comment out next line to crash:
print "PULLTYPES(", k, ")", 'type(k)=', type(k)
if len(k)>5 and k[:5] == 'TTYPE':
col = string.atoi(k[5:])
if col>0 and col<=nc:
o[d[k]] = col-1
return o
Output with print statement in:
...
PULLTYPES( HISTORY ) type(k)= <type 'string'>
PULLTYPES( _FILETYPE ) type(k)= <type 'string'>
PULLTYPES( I_NOISE ) type(k)= <type 'string'>
PULLTYPES( NAXIS2 ) type(k)= <type 'string'>
PULLTYPES( CDELT2 ) type(k)= <type 'string'>
PULLTYPES( CDELT1 ) type(k)= <type 'string'>
...
Output with print statement commented out:
...
Traceback (most recent call last):
File "/u/gpk/f0cls/bin/get_3_f0.sh", line 101, in ?
pegg = get_f0(t + '/pegg.sd', pfile+'.pegg', t + '/pegg');
File "/u/gpk/f0cls/bin/get_3_f0.sh", line 83, in get_f0
return gpkimgclass.read(ttn + '.f0.dat')
File "/home/gpk/lib/gpkimgclass.py", line 41, in read
return gpk_img(hdr, data)
File "/home/gpk/lib/gpkimgclass.py", line 69, in __init__
self.types = _pull_types(self.hdr, self.n[1])
File "/home/gpk/lib/gpkimgclass.py", line 23, in _pull_types
if len(k)>5 and k[:5] == 'TTYPE':
IndexError: list index out of range
...