我只是想一一展示一些数据库的元素:
from twisted.web import server, resource
from twisted.internet import reactor
from pymongo import Connection
import time
import pprint
class ZenResource(resource.Resource):
isLeaf = True
connection = Connection('...', 27017)
db = connection.data
db.authenticate("...","...")
iter = db.index.find()
def render_GET(self, request):
item = self.iter.next()
# ... simple processing, skipped some simple strings manipulations:
htmlLines = []
for textLine in pprint.pformat(item).splitlines():
htmlLines.append('<br/>%s' % textLine)
htmlText = '\n'.join(htmlLines)
request.setHeader("Content-type", 'text/html; charset=UTF-8')
return htmlText.encode("utf8")
reactor.listenTCP(48088, server.Site(ZenResource()))
reactor.run()
在一个系统上(Linux hh 3.0.0-16-generic-pae #28-Ubuntu SMP Fri Jan 27 19:24:01 UTC 2012 i686 i686 i386 GNU/Linux)一切正常。在另一个系统上(Linux localhost 2.6.38-8-server #42-Ubuntu SMP Mon Apr 11 03:49:04 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux)
我得到以下信息:
root@localhost:~# python zen.py
Bus error
我认为两台服务器之间的唯一区别是(除了 x32 / x64 形式)是第二台服务器上有类似的扭曲过程。这个过程做一些重要的事情并且真的不想终止或以任何其他方式干扰它只是为了检查我的测试代码是否有效。