Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8992047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:51:56+00:00 2026-06-15T22:51:56+00:00

We are using momoko and having following standard setup for async connection to db

  • 0

We are using momoko and having following standard setup for async connection to db in tornado application:

class BaseHandler(tornado.web.RequestHandler):
    @property
    def db(self):
        # Create a database connection when a request handler is called
        # and store the connection in the application object.
        if not hasattr(self.application, 'db'):
            self.application.db = momoko.AsyncClient({
                'host': 'localhost',
                'database': 'momoko',
                'user': 'frank',
                'password': '',
                'min_conn': 1,
                'max_conn': 20,
                'cleanup_timeout': 10
            })
        return self.application.db

One day, I found that code like this, will block application:

fail = yield gen.Task(self.db.execute, 'BEGIN; SELECT * FROM non_existing_table; END;')

First idea, that come in head, was:

try:
    fail = yield gen.Task(self.db.execute, 'BEGIN; SELECT * FROM non_existing_table; END;')
except:
    reconnect()

After some digging on subject, I found that it’s better to do something like this:

try:
    fail = yield gen.Task(self.db.execute, 'BEGIN; SELECT * FROM non_existing_table; END;')
except:
    yield gen.Task(self.db.execute, 'ROLLBACK;')

And finally, after exploring source code of momoko I found, that it’s better to use blocking client for transaction.

So BaseHandler transformed into:

class BaseHandler(tornado.web.RequestHandler):
    @property
    def db(self):
        # Create a database connection when a request handler is called
        # and store the connection in the application object.
        if not hasattr(self.application, 'db'):
            self.application.db = momoko.AsyncClient({
                'host': 'localhost',
                'database': 'momoko',
                'user': 'frank',
                'password': '',
                'min_conn': 1,
                'max_conn': 20,
                'cleanup_timeout': 10
            })
        return self.application.db

    @property
    def bdb(self):
        # Create a database connection when a request handler is called
        # and store the connection in the application object.
        if not hasattr(self.application, 'bdb'):
            self.application.bdb = momoko.BlockingClient({
                'host': 'localhost',
                'database': 'momoko',
                'user': 'frank',
                'password': '',
                'min_conn': 1,
                'max_conn': 20,
                'cleanup_timeout': 10
            })
        return self.application.bdb

Now my question… is there any safe way to use transaction in AsyncClient? Or AsyncClient is commonly used for read from database, not for writing/updating data there?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:51:58+00:00Added an answer on June 15, 2026 at 10:51 pm

    I’m working on Momoko 1.0.0 and I just released the first beta. Transactions are one of the new features. Here’s my post on the mailinglist: https://groups.google.com/forum/?fromgroups=#!topic/python-tornado/7TpxBQvbHZM

    Versions before 1.0.0 don’t support transactions, because everytime you run execute there’s a possibility that AsyncClient will pick a new connection for you and you won’t be able to rollback your transaction if anything goes wrong.

    I hope this helps a bit. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the following as an example (with $db being a previously created database connection
Using System.Diagnostics.EventLog .NET type one can programmatically create logs into the Event Viewer application.
using Telerik.WinControls.Data; using Telerik.WinControls.UI.Export; namespace Directory { public partial class radForm : Form {
@using(Html.BeginForm(About, User, FormMethod.Post , new { id=aboutme})) { <fieldset> <ul> <li> <label class=block>About me</label>
Using the following database table structure: Order Table: OrderId OrderName OrderItem Table: OrderId ItemId
Using this code, the following execution yields strange results: C 100 R W The
Using Qt Creator, I have set a QWidget's background property to black. However, some
Using IOS, I am trying to integrate the LinkedIn into the application. The integration
Using Java, how can I extract all the links from a given web page?
Using MongoDB C# Driver (official form 10gen), I'm doing the following code: using (database.RequestStart())

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.