Re: Spyce and SQL Alchemy Questions

Bruce Webber <[email protected]>
Newsgroups gmane.comp.python.spyce.general
Message-ID <3A88FDB5A47C8857343C4AAC@[10.9.30.130]>
I have another question.

My current configuration (which works well so far), looks like this (with 
lots of code left out):

index.spy
---------

[[.import names="pool"]]
[[ import prjStat ]]

[[\
# see if the database needs to be opened
if not pool.has_key('dbOpen'):
    prjStat.openDB()
    pool['dbOpen'] = True

# create database session
dbSession = prjStat.getDBSession()
]]

[[-- code appears here to get and display a list of projects using 
prjStat.getProjects() --]]

[[ dbSession.close() ]]


prjStat.py
----------

from sqlalchemy import *
import prjStatConfig

# classes that represent database rows appears here ...

# this function "opens" the database
def openDB(sDbURL = prjStatConfig.DB_URL):
    global dbEngine

    # create database engine
    dbEngine = create_engine(sDbURL)

    dbMetaData = MetaData()

    # code to define table objects appears here ...
    # code to map table objects to classes appears here ...

# create a session and bind it to the global engine object
def getDBSession():
    return create_session(bind_to = dbEngine)

# various functions to return database objects appear here ...

# end of code

Once openDB() is executed, it does not need to be executed again. The 
dbEngine object and the mappings that are created in dbOpen() persist. So 
the Spyce webserver must be keeping these. Is this because dbEngine is 
global? What is the scope (if that's the right word) for these objects? Are 
they available for the one session only, or across sessions at the 
application level?

Jonathan, in your last message you mentioned thread-safety and that is 
something I do need to learn more about. I'll study up on that.

Thanks!

-- 
Bruce Webber
[email protected]
http://brucewebber.us
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.