Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 0.85 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Sqlalchemy query not consistent between multi tornado instances
  2. topics = self.db.query(Topic).order_by(Topic.updated_at.desc()).limit(20)
  3.        
  4. class Application(tornado.web.Application):
  5. def __init__(self):
  6.     # setup app
  7.     from urls import handlers,ui_modules
  8.     settings = dict(
  9.         debug = options.debug,
  10.         static_path = os.path.join(root_dir, "static"),
  11.         xsrf_cookies = True,
  12.         cookie_secret = "nzjxcjasduuqwheazmu293nsadhaslzkci9023nsadnua9sdads/Vo=",
  13.         ui_modules = ui_modules,
  14.     )
  15.     tornado.web.Application.__init__(self, handlers, **settings)
  16.  
  17.     self.db = scoped_session(sessionmaker(bind=engine,autocommit=False,autoflush=False))
  18.        
  19. class BaseHandler(web.RequestHandler):
  20.     @property
  21.     def db(self):
  22.         return self.application.db
  23.        
  24. topic = Topic()
  25. topic.title = u'abcdefg'
  26. self.db.add(topic)
  27. self.db.commit()