tornado - Does Motorengine mantain an IO stream with mongo db? -
i want use motorengine tornado application. given in docs, how supposed make odm
from motorengine.document import document motorengine.fields import stringfield, datetimefield  class article(document):     title = stringfield(required=true)     description = stringfield(required=true)     published_date = datetimefield(auto_now_on_insert=true)      new_title = "better title %s" % uuid4()  def create_article():     article.objects.create(         title="some article",         description="this article matters.",         callback=handle_article_created     )  def handle_article_created(article):    article.title = new_title    article.save(callback=handle_article_updated)  def handle_article_updated(article):     article.objects.find_all(callback=handle_articles_loaded)  def handle_articles_loaded(articles):     assert len(articles) == 1     assert articles[0].title == new_title     articles[0].delete(callback=handle_article_deleted)  def handle_article_deleted(number_of_deleted_items):     try:         assert number_of_deleted_items == 1     finally:         io_loop.stop()  io_loop.add_timeout(1, create_article) io_loop.start() the confusion is, maintain consistent connection database once instance created ? want non-blocking i/o operations database models it's not problem if does. should not implementing users model access once @ time of verification. there normal way access users data ?
also, i'm unclear few things :
- what last 2 lines (ioloop) doing here? 
- i declaring different models in separate files, do - io_loop.start()each file? part seems weird me.
please me out. thanks.
reading motorengine's code, appears me each operation mongodb, article.objects.create, checks motorclient instance , reuses 1 if possible. here's connection cached , looked cache:
https://github.com/heynemann/motorengine/blob/master/motorengine/connection.py#l62
each motorclient maintains persistent pool of iostreams, answer question yes.
ioloop.start starts application server. should call once, in 1 file. call start runs forever, or until kill process.
the add_timeout call way demonstrate motorengine's functionality, waits 1 second calls create_article. wouldn't in actual application; you'd call create_article directly in requesthandler, without add_timeout.
Comments
Post a Comment