Scott Russell wrote:
> ### Start 2 ##
> class TestPage(Page):
> def writeContent(self):
> peeps = Person.select(Person.q.email=='xxx')
> self.writeln('''Welcome.''')
> ### End 2 ##
Note that this doesn't do anything. When you call .select(), it only
creates a query, it doesn't run it or send anything to the database.
Only when you iterate or get an index will a query happen.
> Once again, this holds up wonderfully. It never fails, as far as I can
> tell. Rock solid.
>
> Now, for the bad one. One more TestPage servlet, this time with an
> accessor for peeps.
>
> ### Start 3 ##
> class TestPage(Page):
> def writeContent(self):
> peeps = Person.select(Person.q.email=='xxx')
> p = peeps[0]
> self.writeln('''Welcome''')
> ### End 3 ##
Now you've actually done something. Which means there's two concurrent
threads hitting the same site.
I've written badly unthreadsafe MySQL code before, and it gives me wonky
results but not a crash like you describe. That's ugly. But I assume
it's some sort of threadsafety issue.
Have you tried turning debugging on in the connection (add debug=1 to
your connection constructor)? Whatever comes before the fall? Each
line starts with a connection ID, which should be useful. Adding the
thread name to DBConnection.printDebug would also probably be useful, like:
def printDebug(self, conn, s, name, type='query'):
if type == 'query':
sep = ': '
else:
sep = '->'
s = repr(s)
n = self._connectionNumbers[id(conn)]
spaces = ' '*(8-len(name))
threadName = threading.currentThread().getName()
print ('%(n)2i:%(threadName)s/%(name)s%(spaces)s%(sep)s %(s)s' %
locals())
Ian
|