MSW crash with <refcnt 0 at ...>

Frank Millman frank at chagford.com
Thu Jun 12 11:39:57 EDT 2003


Hi all

I have an obscure problem with the following piece of code (distilled
from a larger application) -

######################################################

#! /usr/bin/python
import sys

class glob:
    errmsg = 'ok'

if sys.platform == 'win32':
    import odbc
    glob.db = odbc.odbc('frank/Adminstrator')
else:
    import pgdb
    glob.db = pgdb.connect(database='frank')

def update():
    cur = glob.db.cursor()
    try:
        cur.execute("insert into fmtest values ('E001','EFG
Ltd','Eric','1234567')")
        glob.errmsg = ['success']
    except:
        glob.errmsg = ['fail']
        return
    glob.db.commit()

print glob.errmsg
update()
print glob.errmsg

######################################################

Class glob only contains class attributes, and is used to pass globals
around various modules. It has no methods and is never instantiated.

My application works with two databases - PostgreSQL on Redhat 8 using
pgdb, and SQLServer 2000 on Windows 2000 using odbc from Pythonwin.
Python version is 2.2.2 in both cases.

The update routine tries to insert a record into the database. If it
fails because the record already exists, MSW pops up a box with the
message "Python.exe has generated errors and will be closed by
Windows", and the dos box displays the message "<refcnt 0 at ....>".

The error does *not* occur in the following cases -
Under Linux the error never occurs
If the insert succeeds - no error
If the error message is a string or a tuple instead of a list - no
error
If the update routine is part of the main line instead of a function -
no error
The error only occurs when glob.errmsg is accessed. If the last line
is removed - no error

Can anyone explain what is going on? Thanks in advance.

Frank Millman




More information about the Python-list mailing list