Community: Framework mailing list archives

Join thread in odoo framework

tran anh dung
- 10/03/2016 06:10:18
Hi all, I'm trying to make multiple threads in a function by threading.Thread, then I join these thread to main-thread. Before joined, I committed new cursor in each thread. But, in main-thread, I got fail data.

For example: Call function action_activate from another function or from button on form view, action_activate has defined following below:
def _activate(self):
    r = self.with_env(Environment(self.pool.cursor(), self.env.uid, self.env.context)
    # do something
    r.write({'state': 'running'})

def action_activate(self)
    threads = []
    for r in self:
         t = threading.Thread(target=r._activate)
     for t in threads:
     # do somenthing

In another function or call after joined all threads:
     for r in self:
          print r.state #  r.state is not 'running'. But when open database and run sql query, the state is 'running'

Is there anyone now why. I tried to do some ways to reset api.Environment but still fail.
Please help me to resolve it :)


Trần Anh Dũng (.Mr)
Phone: 0989 345 654
Skype: trananhdung1791