On Tue, Feb 18, 2014 at 03:46:23PM -0800, Jeff Dairiki wrote:
> As a workaround, at app config time, right after create_engine is
> called, I execute a query (before there is a possibility of a
> multi-thread race.) E.g.
>
> engine = sa.create_engine(...)
>
> # early query to force dialect.initialize()
> engine.execute(sa.sql.select([1]))
Just in case anyone is using this workaround, (or Mike's
`engine.connect().close()`), a better/safer work-around is:
engine = sa.create_engine(...)
# early query to force dialect.initialize()
conn = engine.connect()
conn.invalidate()
We are running our app using uwsgi which performs the app
initialization (i.e. constructs the uwsgi app) in the master process
before forking the worker processes. Calling just `conn.close()`
returns the initial connection to the connection pool. That
connection is then inherited by each of the worker processes. When
two workers try to use the connection simultaneously, sparks fly.
`.invalidate()` prevents the connection from be re-used by the pool.
Jeff
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.