I've been getting lots of:
  Can't reconnect until invalid transaction is rolled back (original cause: 
InvalidRequestError: Can't reconnect until invalid transaction is rolled 
back)
and sometimes
  "Commands out of sync; you can't run this command now"

And I need to figure out how to avoid this, or recover from it.

I had been trying to recover by doing a DBSession.close at the end of each 
request using 

    config.add_subscriber(clearSession, NewRequest)
and where clearSession does DBSesison.close().

But the problem with that is that my unit tests are the type that start a 
session, and then on tearDown do a rollback.  If the unit test does any 
requests, then the session gets closed in the middle, and I end up with 
some getting committed and some getting rolled back... and the unit test 
tries to read back an update it did, and doesn't see updated data, just the 
original data... so the quick fix breaks my unit tests.

What could I have messed up in my app?  Here's the whole chain:

lighttpd configuration:

server.port = 80
$HTTP["host"] =~ "^<prj>-dev.<company>dev.net|localhost$" {
    server.document-root = "/opt/<prj>/server/"
    $HTTP["url"] !~ "^/static/" {
        scgi.server = ("/" => ((
            "host" => "127.0.0.1",
            "port" => 5000,
            "min-procs" => 1,
            "max-procs" => 3,
            "check-local" => "disable",
            "fix-root-scriptname" => "enable"
        )))
    }
}

supervisord.conf configuration:

[program:cbris]
autorestart=true
command=/opt/env/bin/pserve /opt/<prj>/my.ini
user=jcarroll
process_name=%(program_name)s-%(process_num)01d
numprocs = 1
numprocs_start=0
redirect_stderr=true
stdout_logfile=/opt/<prj>/<prj>.log


my.ini:

[app:main]
use = egg:Server

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes =
    pyramid_mailer
    pyramid_debugtoolbar
    pyramid_tm

sqlalchemy.url = mysql://<prj>:<pass>@localhost/<prj>
sqlalchemy.pool_recycle=120
sqlalchemy.echo_pool=debug

[server:main]
use = egg:Flup#scgi_thread
host = 127.0.0.1
port = 5000

My __init__.py (stripped down a bit) looks like:
 
from .models import DBSession, Base, Settings

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')

    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    config = Configurator(settings=settings)

    config.include('pyramid_beaker')
    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)

    return config.make_wsgi_app()
#

And in my models.py, I do

DBSession = 
scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
# my custom base class...
Base = declarative_base(cls=<customBase>)


Does anyone see what I'm doing incorrectly?  Is there something that I 
could read with the title, "How to make a rock solid pyramid + sqlalchemy + 
mysql application"  ?


-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to