[Twisted-Python] twistd and SqlObject
I'm sure the answer to this question should be obvious, but I can't find it. I've written a twisted server which recieves a request, looks up the requested data in its cache, and returns the data. It accesses its database via SQLObject - the database is small, so I don't care that it blocks. Twisted has certainly made this very simple. I now want to run that same process using twistd (-noy), but SqlObject gives the error Failed to load application: 'NoneType' object has no attribute 'tableExists' on the last line of the listing below, which works fine when run normally. I guess I'm being very naive about the way in which twistd works, but I can't find any comprehensive documentation saying what it does. Thanks for any pointers, Graham import _mysql_exceptions from elementtree.ElementTree import Element, SubElement, ElementTree, parse from twisted.internet import reactor from twisted.web import server from twisted.web.resource import Resource from twisted.web.client import getPage from cStringIO import StringIO import sqlobject import datetime now = datetime.datetime.now cacheDurationDays = 90 __connection__ = sqlobject.MySQLConnection(host='localhost', db='DomainInfoCache', user='root', passwd='chubchub') class CachedDomain(sqlobject.SQLObject): """The table that the data is cached in""" domain = sqlobject.StringCol(length=80) alexa3monthtraffic = sqlobject.FloatCol() lastUpdate = sqlobject.DateTimeCol() domainIndex = sqlobject.DatabaseIndex({'column':domain, 'length':8}) CachedDomain.createTable(ifNotExists=True)
Graham Stratton wrote:
I guess I'm being very naive about the way in which twistd works, but I can't find any comprehensive documentation saying what it does.
This is mostly a problem with the way you use tac files.
Thanks for any pointers,
Avoid putting everything in one file. The .tac file is not really a module and it's 'execfile'd. Change the code to have everything except a very simple and declarative configuration code inside the tac file and put everything else in a separate module. It should work then. -- Valentino Volonghi aka Dialtone Now Running MacOSX 10.4.1 Blog: http://vvolonghi.blogspot.com http://weever.berlios.de
participants (2)
-
Graham Stratton
-
Valentino Volonghi aka Dialtone