Community: Framework mailing list archives

expert-framework@mail.odoo.com

Re: How to get a new cursor on new api on Thread

by
Laurent Mignon - Senior Software Engineer, Acsone
- 09/26/2014 02:38:52
To ensure that the cusror is closed you can also write.

from contextlib import closing
....
new_cr = sql_db.db_connect(self.env.cr.dbname).cursor()
uid, context = self.env.uid, self.env.context
with api.Environment.manage():
    self.env = api.Environment(new_cr, uid, context)
    with closing(self.env.cr):
        ...


On Thu, Sep 25, 2014 at 8:36 PM, Maxim Litnitskiy <litnimaxster@gmail.com> wrote:
The following seem to work reliably:

            new_cr = sql_db.db_connect(self.env.cr.dbname).cursor()
            uid, context = self.env.uid, self.env.context
            with api.Environment.manage():
                self.env = api.Environment(new_cr, uid, context)

                try:
                      ....

                finally:
                    self.env.cr.close()
 

FInally assures that cursor is closed on thready error or exit.

Thanks for advises.

P.S. May be this link can tell more if you are interested - https://github.com/litnimax/odoo-asterisk-dialer/blob/master/models/dialer.py#L218

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-framework-62
Post to: mailto:expert-framework@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe




--
Laurent Mignon
Senior Software Engineer

Tel : +352 20 21 10 20 32
Fax : +352 20 21 10 21
Gsm : +352 691 506 009
Email: laurent.mignon@acsone.eu

Acsone SA, Succursale de Luxembourg
22, Zone industrielle
L-8287 Kehlen, Luxembourg