there are many on this list who dont think very highly of global variables ! :)
id advise using your own create_engine function to keep track of created engines before calling SA's create_engine strategy, and/or monkeypatch sqlalchemy.create_engine to do so: atexit_engines = [] def atexit(): [e.dispose() for e in atexit_engines] import sqlalchemy as sa _old_create_engine = sa.create_engine def create_engine(*args, **kwargs): engine = _old_create_engine(*args, **kwargs) atexit_engines.append(engine) return engine sa.create_engine = create_engine or, if you want to get more OO about it you can make your own EngineStrategy to do it: import sqlalchemy.engine.strategies as strategies atexit_engines = [] class CleanupStrategy(strategies.ThreadLocalEngineStrategy): def __init__(self): EngineStrategy.__init__(self, 'atexit_cleanup') def create(self, *args, **kwargs): engine = super(CleanupStrategy, self).create(*args, **kwargs) atexit_engines.append(engine) return engine CleanupStrategy() engine = create_engine('someengine', strategy='atexit_cleanup') On Jul 23, 2006, at 10:14 PM, Mike Bernson wrote: > I am using threadlocal. > > Is there any global name that I can call in atexit function. The > atexit > function is registered before any database stuff is accessed. The > engine > create is ' engine = create_engine(connect_string, > strategy='threadlocal')'. In the atexit function I just > want to > close out any active because the port will not be there. There are a > number of engine. One is created for each database that I need to > access. > > Michael Bayer wrote: >> maybe engine.dispose() to explicitly close off everything first >> >> >> On Jul 23, 2006, at 6:15 PM, Mike Bernson wrote: >> >>> I am using ssh to port forward the connection to the database. >>> >>> I have some code that execute before any sqlalchemy that sets up a >>> port forward from local host to mysql database host. In this >>> function >>> I do atexit to kill off the ssh that has the port forward. >>> >>> I get a the following error when the program exits: >>> Exception _mysql_exceptions.OperationalError: (2006, 'MySQL >>> server has >>> gone away') in <bound method ConnectionFairy.__del__ of >>> <sqlalchemy.pool.ConnectionFairy object at 0x2aaaad4c8d90>> ignored >>> >>> Is there something that I can put in the atexit function clear up >>> this >>> error ? >>> >>> Is there something I can put as the last statements to be executed >>> that >>> would clean up this error (for normal execution path) >>> >>> The atexit is done so that no matter how the program exits the >>> ssh is >>> killed off. >>> >>> -------------------------------------------------------------------- >>> -- >>> --- >>> Take Surveys. Earn Cash. Influence the Future of IT >>> Join SourceForge.net's Techsay panel and you'll get the chance to >>> share your >>> opinions on IT & business topics through brief surveys -- and earn >>> cash >>> http://www.techsay.com/default.php? >>> page=join.php&p=sourceforge&CID=DEVDEV >>> _______________________________________________ >>> Sqlalchemy-users mailing list >>> Sqlalchemy-users@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users >> >> >> --------------------------------------------------------------------- >> ---- >> Take Surveys. Earn Cash. Influence the Future of IT >> Join SourceForge.net's Techsay panel and you'll get the chance to >> share your >> opinions on IT & business topics through brief surveys -- and earn >> cash >> http://www.techsay.com/default.php? >> page=join.php&p=sourceforge&CID=DEVDEV >> _______________________________________________ >> Sqlalchemy-users mailing list >> Sqlalchemy-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users > > ---------------------------------------------------------------------- > --- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to > share your > opinions on IT & business topics through brief surveys -- and earn > cash > http://www.techsay.com/default.php? > page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Sqlalchemy-users mailing list > Sqlalchemy-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users