[Twisted-Python] Using sqlalchemy in twisted.
newptcai at gmail.com
Thu Mar 5 02:38:43 EST 2009
I changed my code to this style, it works again.
This code would create a new session on each request and close it
Hope this trick could save me!
'''create and close session for each synchronous method'''
def wrapper(model, *args, **kw):
sess = model.Session()
return f(model, sess, *args, **kw)
def __init__(self, conn_str):
self.conn_str = conn_str
self.engine = create_engine(self.conn_str, echo=False)
self.Session = sessionmaker(bind =
def getObjectById(self, klass, id):
return threads.deferToThread(self._getObjectById, klass, id)
def _getObjectById(self, sess, klass, id):
On Thu, Mar 5, 2009 at 4:29 AM, Valentino Volonghi <dialtone at gmail.com>wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> On Mar 4, 2009, at 11:15 AM, Chris Foster wrote:
> I think SQLAlchemy's ORM might work fine with Twisted. Check out
>> http://foss.eepatents.com/sAsync/ . sAsync doesn't appear to be widely
>> used, but I got the examples to run with some minor changes to the sqlite
>> connection. I'm hoping to try something useful in the next week or two.
> sAsync repository hasn't changed since about 1 or 2 years ago. Now
> sqlalchemy 0.5
> changed quite a bit of the internals and so on. Notice however that the
> tests for
> sAsync use sqlite that is limited essentially to 1 connection, which goes
> back to
> your original discontent.
> I tried to integrate sqlalchemy ORM in the past and it never worked right
> the code in the objects didn't know that it was dealing with twisted and
> sqlalchemy is mainly used in a single thread, it's thread safe but that
> doesn't mean
> that you can share objects between threads.
> - --
> Valentino Volonghi aka Dialtone
> Now running MacOS X 10.5
> Home Page: http://www.twisted.it
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (Darwin)
> -----END PGP SIGNATURE-----
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
look to the things around you,the immediate world around you, if you are
alive,it will mean something to you ——Paul Strand
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python