FSX / momoko

Wraps (asynchronous) Psycopg2 for Tornado.
http://momoko.61924.nl/
Other
362 stars 73 forks source link

TypeError: putconn() got an unexpected keyword argument 'callback' #82

Closed encorehu closed 9 years ago

encorehu commented 9 years ago
It important to return connection back to the pool once you’ve done with it, 
even if an error occurs in the middle of your work. 
Use either putconn() method or manage() manager to return the connection.

so. i tried this example:

@gen.coroutine
def get(self):
    chunk = 1000
    try:
        connection = yield momoko.Op(self.db.getconn)
        with self.db.manage(connection):
            yield momoko.Op(connection.execute, "BEGIN")
            ...
    except Exception as error:
        self.write(str(error))
    finally:
        yield momoko.Op(self.db.putconn, connection)

but error occured:

TypeError: putconn() got an unexpected keyword argument 'callback'

and i found solution, add param callback=None to putconn function at connection.py line 444:

    def putconn(self, connection, callback=None):

and it should be fixed, but i've not test this

encorehu commented 9 years ago
    @contextmanager
    def manage(self, connection):
        """
        Context manager that automatically returns connection to the pool.
        ...

my fault, plz close this issue

haizaar commented 9 years ago

putconn is not an async operation - it does its job immediately, i.e. no need to yield it to Tornado. Just do self.db.putcon(connection) in your finally clause or use manager.