On Mon, May 3, 2010 at 7:35 PM, writes_on <[email protected]> wrote:
>
> Hi all,
>
> I've been building some Web 2.0 style Intranet applications for awhile for
> my job using Pylons, and really enjoying it. We use SQLAlchemy to access the
> backend MySQL database and that is working fine. Which leads me to my
> question: how does Pylons handle using multiple threads for HTTP requests
> that access the database using SQLAlchemy when doing so with MySQL isn't
> thread safe? I ask because I'd like to learn how it's done so I can perhaps
> port the technique to some Twisted server apps we've written that we'd like
> to have use SQLAlchemy as well.
>
> All help, suggestions, pointers, etc. would be most helpful!
> Thanks in advance,
> Doug

The features to do this are built into SQLAlchemy.  Most Pylons apps
use a scoped session, which is thread local.

http://www.sqlalchemy.org/docs/session.html?highlight=scoped%20session#contextual-thread-local-sessions

If you create a default Pylons application and answer 'yes' to the
SQLAlchemy option, it puts a scoped session in the model, and clears
out at the end of each request in the base controller.

If you aren't using the ORM and thus don't need a session, you can
execute queries on the engine directly, which checks out a pooled
connection for the query, or you can explicitly check out a connection
for the duration of the request. But don't share connections between
requests.

Here's the Pylons documentation on it. This is the development version
so it may not be quite finished.

http://pylonshq.com/docs/en/1.0/models/
http://pylonshq.com/docs/en/1.0/advanced_models/

-- 
Mike Orr <[email protected]>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to