On Aug 12, 2010, at 5:10 AM, Faheem Mitha wrote:

> 
> Hi,
> 
> I'm using scoped_session with PostgreSQL to run multiple threads, each thread 
> creating a table.

Its generally a poor application practice for an application to need new 
permanent tables on the fly.   I think reddit's application might do this, but 
its considered poor design.  Database schemas are supposed to be fixed.


> However, I'm getting some pretty weird and inconsistent errors (segfaults 
> from Python with some very peculiar errors), and I was wondering if my usage 
> was at fault.
> 
> The program has a serial bit, and a parallel bit, and currently I'm doing 
> something like this. For the serial bit I do
> 
> db = create_engine(dbstring)
> Session = sessionmaker()
> session = Session(bind=db)
> 
> and then later I do
> 
> session.close()
> 
> db = create_engine(self.dbstring)
> Session = scoped_session(sessionmaker())
> Session.configure(bind=db)
> 
> Looking at this is seems likely that is would be better to just use 
> scoped_session everywhere, that is, just start with
> 
> db = create_engine(self.dbstring)
> Session = scoped_session(sessionmaker())
> Session.configure(bind=db)
> [proceed with using Session in serial mode and eventually use it in parallel 
> mode too]
> 
> I'm basically writing to confirm that it is Ok to use scoped_session in this 
> way. The way I'm doing it looks a little dodgy. I don't know if this is 
> really the cause of my problem - just clutching at straws here. Thanks in 
> advance. Please CC me on any reply.

you can make as many scoped_sessions, metadatas, etc. as you want, none of that 
would cause a segfault.    They are just Python objects.     Its only if you 
share a psycopg2 connection between threads and have different threads hammer 
on it simultaneously that there would be issues like that.    If you have a 
single session, and share that among threads who access it concurrently, this 
will produce that result.     There should be no need to guess about it.  If 
multiple threads are hitting the session you have above, then that's a likely 
cause of your issue.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to