[sqlalchemy] Re: Using sqlalchemy in twisted.

2009-03-16 Thread Jeff FW
Pedro, I don't really have much of anything special as far as the connection goes--SQLAlchemy already does a pretty awesome job of handling all that for you. I just keep a module-level variable that I can import as needed, and call a function in that module to set up the connection with

[sqlalchemy] Re: Using sqlalchemy in twisted.

2009-03-15 Thread Pedro Algarvio, aka, s0undt3ch
On Mar 11, 2:13 pm, 一首诗 newpt...@gmail.com wrote: Hi Jeff, In my project I use the *model* to indicate an instance of Database. I don't really need multiple instances of Database. But when I wrote unit test, I always create an new one database in setup, which create a new sqlite in

[sqlalchemy] Re: Using sqlalchemy in twisted.

2009-03-11 Thread Jeff FW
Logging SA objects *after* the session is gone will always be a problem, unless you make sure to detach all of them from the session. I'd just log the original request, instead. In my case, I have to convert all of my SA objects to something Perspective Broker understands, so I actually log

[sqlalchemy] Re: Using sqlalchemy in twisted.

2009-03-11 Thread 一首诗
Hi Jeff, In my project I use the *model* to indicate an instance of Database. I don't really need multiple instances of Database. But when I wrote unit test, I always create an new one database in setup, which create a new sqlite in memory database to avoid conflicts between test cases. About

[sqlalchemy] Re: Using sqlalchemy in twisted.

2009-03-10 Thread 一首诗
Hi Jeff, Thanks for your kind suggestion. I first add some log decorators, but i found when it might cause to print sqalchemy objects which has not been bound to any session. And I am not quite sure about how to make the decorator mor genreal. Actually, I think I must use model as the first

[sqlalchemy] Re: Using sqlalchemy in twisted.

2009-03-05 Thread Jeff FW
Don't use scoped_session--you'll run into problems no matter what you do. I'm using Perspective Broker from Twisted with SQLAlchemy. I make sure to create and commit/rollback a session for *every* PB request. It works perfectly, and that's the only way I was really able to get it to work in

[sqlalchemy] Re: Using sqlalchemy in twisted.

2009-03-04 Thread Gunnlaugur Briem
Hi 一首诗, what database engine are you using? On PostgreSQL at least, table creation and dropping (and some other operations) take an ACCESS EXCLUSIVE lock on the database, and will wait for this lock indefinitely if there are open transactions hanging around. My app creates and drops tables

[sqlalchemy] Re: Using sqlalchemy in twisted.

2009-03-04 Thread 一首诗
I'm not quite sure, but I think I'm pretty careful of sharing objects between threads. 1st, I only cached as few as possible orm objects. I tried to detach them, but I found that if I detach them, I can't access any of their fields any more. 2nd, I create new orm objects based on client