[Twisted-Python] Newbie - how to modify my db-intensive app touseTwisted
Henning.Ramm at mediapro-gmbh.de
Henning.Ramm at mediapro-gmbh.de
Mon Nov 21 04:45:27 EST 2005
My actual project is similar:
Several different apps need a database connection, but instead I let them connect via Twisted PB to a Proxy that keeps the only db conn.
I fixed most of my troubles using Interaction and 'lock tables' in them (MySQL or at least the Python driver doesn't support real transactions).
example:
# self.dbpool = adbapi.ConnectionPool(self.dbApiName, **Conf)
def remote_deleteOld(self, days=21):
try:
d = self.dbpool.runInteraction(self._deleteOld, days)
d.addErrback(self.errorHandler, 'deleteOld', days)
return d
except Exception, ex:
self.log.error(ex)
return defer.fail(ex)
def _deleteOld(self, txn, days):
rows = [0,0,0,0]
# lock tables
try:
txn.execute("delete from t5 where t5_date < CURDATE() - INTERVAL %d DAY" % days)
res = txn.fetchall()
except _mysql_exceptions.Warning, text:
self.log.info(text)
if res: rows[3] = int(res[0][0])
# ...
# unlock tables
return tuple(rows)
HTH
Best regards,
Henning Hraban Ramm
Südkurier Medienhaus / MediaPro
Support/Admin/Development Dept.
More information about the Twisted-Python
mailing list