0

我有这个错误:

[E 130328 12:04:09 ioloop:481] Error in periodic callback
    Traceback (most recent call last):
      File "/usr/lib/python2.6/site-packages/tornado/ioloop.py", line 479, in _run
        self.callback()
    TypeError: unbound method check_commands_response() must be called with CheckCommandResponse instance as first argument (got nothing instead)

我有这部分代码:

class CheckCommandResponse(BaseHandler):
    @tornado.web.authenticated
    @tornado.web.asynchronous
    @tornado.gen.engine
    def check_commands_response(self):
        self.lock_tables("read", ['networks'])
        nets = self.db.query("SELECT DISTINCT netid from networks")
        self.unlock_tables

        for net in nets:
            got_commands_response(net)

    def got_commands_response(netid):
        como_url = "".join("http://131.114.52.207:44444/ztc_config?netid=" \
                   + netid + "&opcode_group=0&opcode=0&start=-10s&end=-1s")

        http_client = AsyncHTTPClient()
        #asynchronous alternative to time.sleep
        yield tornado.gen.Task(tornado.ioloop.IOLoop.instance().add_timeout, time.time() + 5)
        response = yield tornado.gen.Task(http_client.fetch, como_url)

        print response

################################################################################
# Application Entry Point
################################################################################
def main():
    tornado.options.parse_command_line()
    http_server = tornado.httpserver.HTTPServer(Application())
    http_server.listen(options.port)
    periodic = tornado.ioloop.PeriodicCallback(CheckCommandResponse.check_commands_response, 5000)
    periodic.start()
    tornado.ioloop.IOLoop.instance().start()

我必须实例化主类?有什么错误?

编辑

BaseHandler 类是这样的:

###############################################################################
# Base handler. All the handlers should inherit from it.
###############################################################################
class BaseHandler(tornado.web.RequestHandler):
    @property
    def db(self):
        return self.application.db

    # utility functions for tables LOCK/UNLOCK
    def lock_tables(self, lock_type, tables):
        assert(tables != None)
        assert(lock_type.upper() in ["READ", "WRITE"])
        tables = map(lambda x: x + " " + lock_type, tables)
        self.db.execute("LOCK TABLES " + (", ".join(tables)))

    def unlock_tables(self):
        self.db.execute("UNLOCK TABLES")
4

0 回答 0