Community: Framework mailing list archives

expert-framework@mail.odoo.com

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

by
Maxim Litnitskiy
- 09/25/2014 14:22:19
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