Latest Version: 0.9.6.2
  Dashboard > Pylons Cookbook > ... > Deployment > Issues with long-running Pylons processes
  Pylons Cookbook Log In | Sign Up   View a printable version of the current page.  
  Issues with long-running Pylons processes
Added by Max Ischenko, last edited by Max Ischenko on Apr 19, 2007  (view change)
Labels: 
(None)

When your Pylons application remains running for a long time (as opposed to one-off request handling) some unique issues often arise. This page tries to list known issues and provide solution or a workaround.

Timed-out database connections (MySQL)

MySQL typically has an idle timout for connections (on Ubuntu it is set by default to 8 hours). This means if no-one uses your app for 8 hours, open database connection silently 'expires' and next attempt to do a database query will result in: OperationalError: (2013, 'Lost connection to MySQL server during query').

MySQLdb python module doesn't provide the code to deal with this (e.g. to re-connect automatically) so this becomes your responsibility. Popular ORMs (such as SQLObject and SQLAlchemy) provides some workarounds though.

If you are using SQLAlchemy you should use a connection pool and specify the pool_recycle option to be less than the connection timeout so that SQLAlchemy re-creates the connection. See http://www.sqlalchemy.org/docs/dbengine.myt for more information.

SQLObject 0.8 attempts to re-execute query up to three times if SERVER_LOST or SERVER_GONE errors are reported by MySQLdb.

If all above fails, you can setup a cron task which will ping your server regularly and prevent db connection to expire, e.g. wget http://localhost:5009/.

Site running on a free Atlassian Confluence Open Source Project License granted to Pylons. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.3.3 Build:#645 Feb 13, 2007) - Bug/feature request - Contact Administrators
Top