sot/mica

Fix the daily error in mica processing

Closed this issue · 3 comments

Each day the mica processing log ends with something like:

<<2013-Nov-29 04:34>> Exception AttributeError: "'NoneType' object has no attribute 'debug_msg'" in <bound method Connection.__del__ of <Sybase.Connection instance at 0x47f8518>> ignored

My guess is that there is a problem disconnecting from the database when the program shuts down and does garbage collection. Best to explicitly close the database connection (in fact this should be the general rule). This reveals a secondary issue which is opening a database handle on module import. Best to avoid significant side effects of importing a module. There is a line though, and I think that defining a logger on import is OK. So do something like:

def main():
    global ACA_DB  # Persistent global so use uppercase
    ACA_DB = Ska.DBI.DBI(dbi='sybase', server='sybase', user='aca_read')            
    ...
    ACA_DB.conn.close()

On Sat, Nov 30, 2013 at 7:53 AM, Tom Aldcroft notifications@github.comwrote:

Each day the mica processing log ends with something like:

<<2013-Nov-29 04:34>> Exception AttributeError: "'NoneType' object has no attribute 'debug_msg'" in <bound method Connection.del of <Sybase.Connection instance at 0x47f8518>> ignored

My guess is that there is a problem disconnecting from the database when
the program shuts down and does garbage collection. Best to explicitly
close the database connection (in fact this should be the general rule).

In other code, I'd been doing an explicit delete of the database handle.
Good enough? Or is the close() cleaner?

Even when you delete an object there is no guarantee when garbage collection will do it. Safest is to close then delete. In general every file like object should always be closed explicitly.

Should be complete with 8dbf394