2

This is very similar to Python asynchronous processing in existing loop; I have a time consuming python method that needs to be run (user initiated) asynchronously so user can keep working on something else while method is running on the backend.

I am using threading but cursor gets closed and I have to re-create it, and when writing to DB I am getting the error 'GeneratorContextManager' object has no attribute 'dbname'.

My simplified code:

    import threading

    def call_validar(self, cr, uid, ids, context=None):
        t = threading.Thread(target=self.test_threading, args=(cr, uid, ids, context,))
        t.start()
        return True

    def test_threading(self, cr, uid, ids, context=None):   
        for id in ids:
            my_cr = self.pool.cursor()  # Cursor needs to be re-created            
            try:
                self.write(my_cr, uid, id, {'validation_logs': 'Just anything'})    
            except Exception, e:     # 'GeneratorContextManager' object has no attribute 'dbname'   
                _logger.info('Error e [%s] context [%s]' % (e,context))             
        return True

What I am missing?

Mayte

Community
  • 1
  • 1
Mayte
  • 21
  • 1
  • What exactly do you need to do with a running process in background? – Juan Salcedo Jan 07 '16 at 20:04
  • Script loads sale data from a REST server and process it on OpenERP (sale.order, account.invoice, account,voucher,account.move,stock.move, etc), an average of 150 sales. Currently process is done thru a Scheduler but now we need it as user initiated. – Mayte Jan 11 '16 at 15:34

0 Answers0