engine.close() ?

3,449 views
Skip to first unread message

Michael Hipp

unread,
Mar 2, 2012, 11:58:46 AM3/2/12
to sqlalchemy
Is there anything that should be done to close an engine just before
application termination?

I don't see a .close() method but there is a .dispose() method.

Thanks,
Michael

Michael Bayer

unread,
Mar 2, 2012, 1:19:43 PM3/2/12
to sqlal...@googlegroups.com
DBAPI connections typically know how to disconnect when they're deleted, as do socket connections, so there's not particularly any kind of "cleanup" needed when an application exits.

The one kind of warning you can get on app exit are weakref warnings, for connections that haven't been returned to the connection pool. These warnings are of course entirely harmless, but to avoid them you can make sure all connections are back in the pool, with the ORM this means any Session object has been completed with commit(), rollback(), or close(). If using the Core is means all Connection and ResultProxy objects have been closed.

engine.dispose() will actively close out connections that are present in the pool and not checked out, but this is mostly to help with test suites that setup/teardown lots of engines as well as when the database has been restarted to flush the entire connection pool.

> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>

Reply all
Reply to author
Forward
0 new messages