[egenix-users] Exception exceptions.AttributeError - Depending upon the naming of the module ( connector.py / error_connector.py)

M.-A. Lemburg mal at egenix.com
Wed Feb 11 18:29:19 CET 2009


On 2009-02-11 14:24, M.-A. Lemburg wrote:
> On 2009-02-11 13:14, Senthil Kumaran wrote:
> Here's a typical example of how you'd use mxODBC Connect:
> 
> from mx.ODBCConnect.Client import ServerSession
> 
> def main():
> 
>     # Setup a server session
>     session = ServerSession(config_file='client-config.ini')
> 
>     # Connect to the mxODBC Connect Server
>     db_api = session.open()
> 
>     # Connect to a database
>     connection = db_api.DriverConnect('DSN=...;UID=...;PWD=...')
> 
>     # Process data on the connection
>     ...
> 
>     # Finalize the connection
>     connection.close()
> 
>     # Finalize the server session
>     session.close()
> 
> Note that there are no module global being used. This assures that
> you have controlled garbage collection.

Here's an easy fix for the situation where you have the session
object defined as module global:

# Register atexit function
import atexit
atexit.register(session.close)

Such exit functions are called at Python shutdown time, but just
before the interpreter gets finalized, ie. all modules are still
available, so all the connections of the session get closed properly.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Feb 11 2009)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/



More information about the egenix-users mailing list