Technical mailing list archives

Re: Join thread in odoo framework

Roel Adriaans
- 10/03/2016 06:36:10
Hello Trần Anh Dũng,

I think that creating threads that way is not correct and you can get a lot of unwanted side effects.

What you can do, and we often do for parallel processing is using the odoo connector framework.
Then you can create jobs that can run in parallel, and do this in a clean way. If one of the batches fail, the other jobs have no issues.


Met vriendelijke groet,
With kind regards, 

Roel Adriaans

2016-10-03 12:13 GMT+02:00 Anh Dũng Trần <>:
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

Post to: