OK, I've been going about reforming SA's resource management in the wrong[1] 
way[2]. I've been trying to refactor the main API of SA's ORM to externalize 
the resource management. Instead, I should have been working on the internal 
implementations of objects like Engine, Table, Mapper, ect.

Note: When I talk about resources I mean database connections and objects that 
manage them (engine, session, etc).

It has been mentioned that other frameworks could be built on top of SA. 
However, I'm predicting that this will not happen until resource management is 
completely decoupled from SQL construction. Internally, SA uses the 
thread-local pattern extensively to manage it's resources. This is nice because 
it takes care of some thread-safety issues, but it's bad because it allows a 
sloppy coding style that ignores resource management. Thread local is great in 
some contexts such as web apps where each request is short and discrete (i.e. 
short enough for a connection to be open for the entire duration of the request 
processing on the server). But in other environments this will not work at all.

It has been pointed out that SA depends on __del__ to clean up its resources. 
This is very bad. One reason for this is that the Python garbage collector 
cannot cleanup circularly referenced graphs of objects if __del__ is 
involved[3]. In an ORM, resource management must be totally explicit and 
customizable to allow applications to scale in varying environments. 
Application developers need to be able to control when and how resources are 
obtained and released. Finally, resource management is orthogonal to the real 
job of SA, which is to map database data to objects.

From this point forward, I will attempt to refactor resource handling in a way 
that has less impact on the existing API of SQLAlchemy.

~ Daniel

[1] http://article.gmane.org/gmane.comp.python.sqlalchemy.user/1311
[2] http://article.gmane.org/gmane.comp.python.sqlalchemy.user/1329
[3] http://docs.python.org/ref/customization.html#l2h-175
See also: "The trouble with Finalizers" here http://arctrix.com/nas/python/gc/



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to