4

2 つのトルネード インスタンスを開始します。tornado-8000 と tornado-8001、アップストリームで nginx を使用。

あるインスタンスにデータを挿入すると、別のインスタンスのクエリでこのデータが見つかりません。

SQLAlchemy クエリは次のとおりです。

topics = self.db.query(Topic).order_by(Topic.updated_at.desc()).limit(20)

そして、私の SQLAlchemy は次のように初期化されます:

class Application(tornado.web.Application):
    def __init__(self):
        # setup app
        from urls import handlers,ui_modules
        settings = dict(
            debug = options.debug,
            static_path = os.path.join(root_dir, "static"),
            xsrf_cookies = True,
            cookie_secret = "nzjxcjasduuqwheazmu293nsadhaslzkci9023nsadnua9sdads/Vo=",
            ui_modules = ui_modules,
        )
        tornado.web.Application.__init__(self, handlers, **settings)

        self.db = scoped_session(sessionmaker(bind=engine,autocommit=False,autoflush=False))

ベースハンドラー:

class BaseHandler(web.RequestHandler):
    @property
    def db(self):
        return self.application.db

私の挿入:

topic = Topic()
topic.title = u'abcdefg'
self.db.add(topic)
self.db.commit()

エラーはどこにありますか?

4

1 に答える 1

5

@van さん、ありがとうございます。解決しました。tornado.web.RequestHandler の on_finish メソッドをオーバーライドし、session.remove() を追加しました。

于 2012-05-04T16:15:29.490 に答える