<div>I changed my code to this style, it works again.</div><div><br></div><div>This code would create a new session on each request and close it immediately.</div><div><br></div><div>Hope this trick could save me!</div><div>
<br></div><div>#=========================================</div><div><br></div><div><div>def require_session(f):</div><div>    &#39;&#39;&#39;create and close session for each synchronous method&#39;&#39;&#39;</div><div>    def wrapper(model, *args, **kw):</div>
<div>        sess = model.Session()</div><div>        try:</div><div>            return f(model, sess, *args, **kw)</div><div>        finally:</div><div>            sess.close()</div><div>    return wrapper</div></div><div>
<span class="Apple-style-span" style="border-collapse: collapse; font-size: 18px; "><p>class Database() <br>    def __init__(self, conn_str): <br>        self.conn_str = conn_str <br>        self.engine = create_engine(self.conn_str, echo=False) <br>
        self.Session = sessionmaker(bind = self.engine,  expire_on_commit=False)<br></p><p>    def getObjectById(self, klass, id): <br>        return threads.deferToThread(self._getObjectById, klass, id) <br></p><p>    @<span class="Apple-style-span" style="border-collapse: separate; font-size: 20px; ">require_session<span class="Apple-style-span" style="border-collapse: collapse; font-size: 18px; "></span></span></p>
<p><span class="Apple-style-span" style="border-collapse: separate; font-size: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 18px; ">    def _getObjectById(self, sess, klass, id): </span></span></p>
<p><span class="Apple-style-span" style="border-collapse: separate; font-size: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 18px; ">        return sess.query(klass).get(id) </span></span></p>
</span></div>#=========================================<br><br><div class="gmail_quote">On Thu, Mar 5, 2009 at 4:29 AM, Valentino Volonghi <span dir="ltr">&lt;<a href="mailto:dialtone@gmail.com">dialtone@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">-----BEGIN PGP SIGNED MESSAGE-----<br>
Hash: SHA1<br>
<br>
<br></div><div class="im">
On Mar 4, 2009, at 11:15 AM, Chris Foster wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I think SQLAlchemy&#39;s ORM might work fine with Twisted.  Check out <a href="http://foss.eepatents.com/sAsync/" target="_blank">http://foss.eepatents.com/sAsync/</a> .  sAsync doesn&#39;t appear to be widely used, but I got the examples to run with some minor changes to the sqlite connection.  I&#39;m hoping to try something useful in the next week or two.<br>

</blockquote>
<br>
<br></div>
sAsync repository hasn&#39;t changed since about 1 or 2 years ago. Now sqlalchemy 0.5<br>
changed quite a bit of the internals and so on. Notice however that the tests for<br>
sAsync use sqlite that is limited essentially to 1 connection, which goes back to<br>
your original discontent.<br>
<br>
I tried to integrate sqlalchemy ORM in the past and it never worked right because<br>
the code in the objects didn&#39;t know that it was dealing with twisted and because<br>
sqlalchemy is mainly used in a single thread, it&#39;s thread safe but that doesn&#39;t mean<br>
that you can share objects between threads.<div class="im"><br>
<br>
- --<br>
Valentino Volonghi aka Dialtone<br>
Now running MacOS X 10.5<br>
Home Page: <a href="http://www.twisted.it" target="_blank">http://www.twisted.it</a><br>
<a href="http://www.adroll.com" target="_blank">http://www.adroll.com</a><br>
<br>
-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG v1.4.9 (Darwin)<br>
<br></div>
iEYEARECAAYFAkmu5KoACgkQ9Llz28widGWBWwCglXIKPUFaGbk5tI9XmtrH8lH+<br>
7woAnjrWWWEj2P78szZbNyLzSx0kgz4B<br>
=9uZo<div><div></div><div class="h5"><br>
-----END PGP SIGNATURE-----<br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>look to the things around you,the immediate world around you, if you are alive,it will mean something to you ——Paul Strand<br>