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