On Nov 15, 2008, at 10:33 PM, Randy Syring wrote: > Thank you so much for your response, I am extremely grateful. > However, I am still getting exceptions thrown from SQLite for sharing > connections across threads.
Unfortuantely I cant reproduce your error now, whereas it was quite frequent earlier. Attached is a full test script. If the error you're getting is only with the ISAPI library you're using, that may be part of the problem. > > Are you sure this isn't a problem with pulling the wrong connection > from the pool? > I was able to use a NullPool successfully to alleviate my problems. > However, it still doesn't seem right that I can't get singleton thread > pooling to work. Am I still doing something wrong? The SingletonThreadPool in SQLA 0.5 uses Python's threading.local() to maintain the connection and is extremely simple. SQLA doesn't spawn any threads and only works within the thread from which is was invoked, with the huge asterisk that Python's gc.collect() can invoke cleanup operations in an asynchronous thread, but even in that case the SingletonThreadPool never associates the connection with the threading.local() a second time. Just read the source and try experimenting with it. If you do test with too many threads, the Python interpreter itself may be failing in some way. If I run ab against this script with more than 20 or 30 threads I get a broken socket almost immediately. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
### sqlalchemyapp.py import logging import thread import time from sqlalchemy.orm import sessionmaker, scoped_session from sqlalchemy import create_engine from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey, Unicode from sqlalchemy.orm import mapper logging.basicConfig() logging.getLogger('sqlalchemy.pool').setLevel(logging.INFO) logging.getLogger('').setLevel(logging.INFO) engine = create_engine('sqlite:///test.sqlite') metadata = MetaData() postings_table = Table('employers_postings', metadata, Column('id', Integer, primary_key=True), Column('title', Unicode(150)), Column('education', Unicode(150)) ) class Posting(object): def __init__(self,title, education): self.title = title self.education = education def __repr__(self): return '[Posting "%s" : %d]' % (self.title, self.id) mapper(Posting, postings_table) Session = scoped_session(sessionmaker(bind=engine)) ## WSGI application, called on each request def sqlapp(environ, start_response): # this helps to make IIS use more than one thread time.sleep(0.5) sess = Session() exclogged = False try: logging.info('(%d) start response' % thread.get_ident()) if environ['PATH_INFO'] == '/add': p = Posting(u'test', u'posting') sess.add(p) sess.commit() retval = 'posting added' elif environ['PATH_INFO'] == '/setup': metadata.create_all(bind=engine) retval = 'tables created' else: try: postings = sess.query(Posting).all() except Exception, e: logging.info('(%d) query exception: %s' % (thread.get_ident(), str(e))) exclogged=True retval = 'Postings: \n\n%s' % postings start_response('200 OK', [('content-type', 'text/html')]) return [retval] except Exception, e: if not exclogged: logging.info('(%d) exception: %s' % (thread.get_ident(), str(e))) finally: try: Session.remove() except Exception, e: logging.info('(%d) finally exception: %s' % (thread.get_ident(), str(e))) logging.info('(%d) end response' % thread.get_ident()) from wsgiutils import wsgiServer server = wsgiServer.WSGIServer (('localhost', 8000), {"/":sqlapp}) server.serve_forever()