Hi, all
<br> <p>I am using sqlalchemy in twisted in my project in the way below.
<br> Defer any database operation so the twisted's main thread won't be
<br> blocked.
<br> </p><p>And I use scoped_session, so that sessions won't have to be created
<br> again and again.
<br> </p><p>======================================
<br> 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 = scoped_session(sessionmaker(bind = self.engine,
<br> expire_on_commit=False))
<br> </p><p> def getObjectById(self, klass, id):
<br> return threads.deferToThread(self._getObjectById, klass, id)
<br> </p><p> def _getObjectById(self, klass, id):
<br> sess = self.Session()
<br> return sess.query(klass).get(id)
<br> ======================================
<br> </p><p>The code doesn't work. When I limit the thread numbers to 1
<br> </p><p> reactor.suggestThreadPoolSize(1)
<br> </p><p>Everything goes fine. Other wise the server would be blocked and must
<br> be killed by "kill 9 ...".
<br> </p><p>The result conflicts with my understanding of sqlalchemy. Since I
<br> don't share any object between threads, there should be no problem!
<br> </p><p>Ah.... It always have risk to use something you haven't tried
<br> before ....
</p>I think I have no choice but always set thread pool size to 1 ...<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>