Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
5013 Widoki

Hi every one, I need to execute a payroll for more than 6K employees. This takes about 4 hours to complete.

I want to parallelize the method that compute and confirms the payroll but it throws this error message:

Traceback (most recent call last):

  File "/home/matos/PycharmProjects/Odoo12/odoo/odoo/http.py", line 654, in _handle_exception

    return super(JsonRequest, self)._handle_exception(exception)

  File "/home/matos/PycharmProjects/Odoo12/odoo/odoo/http.py", line 312, in _handle_exception

    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])

  File "/home/matos/PycharmProjects/Odoo12/odoo/odoo/tools/pycompat.py", line 87, in reraise

    raise value

  File "/home/matos/PycharmProjects/Odoo12/odoo/odoo/http.py", line 696, in dispatch

    result = self._call_function(**self.params)

  File "/home/matos/PycharmProjects/Odoo12/odoo/odoo/http.py", line 344, in _call_function

    return checked_call(self.db, *args, **kwargs)

  File "/home/matos/PycharmProjects/Odoo12/odoo/odoo/service/model.py", line 97, in wrapper

    return f(dbname, *args, **kwargs)

  File "/home/matos/PycharmProjects/Odoo12/odoo/odoo/http.py", line 337, in checked_call

    result = self.endpoint(*a, **kw)

  File "/home/matos/PycharmProjects/Odoo12/odoo/odoo/http.py", line 939, in __call__

    return self.method(*args, **kw)

  File "/home/matos/PycharmProjects/Odoo12/odoo/odoo/http.py", line 517, in response_wrap

    response = f(*args, **kw)

  File "/home/matos/PycharmProjects/Odoo12/odoo/addons/web/controllers/main.py", line 966, in call_button

    action = self._call_kw(model, method, args, {})

  File "/home/matos/PycharmProjects/Odoo12/odoo/addons/web/controllers/main.py", line 954, in _call_kw

    return call_kw(request.env[model], method, args, kwargs)

  File "/home/matos/PycharmProjects/Odoo12/odoo/odoo/api.py", line 749, in call_kw

    return _call_kw_multi(method, model, args, kwargs)

  File "/home/matos/PycharmProjects/Odoo12/odoo/odoo/api.py", line 736, in _call_kw_multi

    result = method(recs, *args, **kwargs)

  File "/home/matos/PycharmProjects/Odoo12/payroll/payroll_masive/models/payslip_run.py", line 70, in compute_and_confirm_sheet_massive

    pool.map(self.excec, [slip for slip in slip_list_par])

  File "/usr/lib/python3.6/multiprocessing/pool.py", line 288, in map

    return self._map_async(func, iterable, mapstar, chunksize).get()

  File "/usr/lib/python3.6/multiprocessing/pool.py", line 670, in get

    raise self._value

  File "/usr/lib/python3.6/multiprocessing/pool.py", line 450, in _handle_tasks

    put(task)

  File "/usr/lib/python3.6/multiprocessing/connection.py", line 206, in send

    self._send_bytes(_ForkingPickler.dumps(obj))

  File "/usr/lib/python3.6/multiprocessing/reduction.py", line 51, in dumps

    cls(buf, protocol).dump(obj)

_pickle.PicklingError: Can't pickle <class 'odoo.api.hr.payslip.run'>: attribute lookup hr.payslip.run on odoo.api failed

Does anyone of you have any idea of why is this and how to solve it?

Thank you very much.


Awatar
Odrzuć
Najlepsza odpowiedź

you can't  pickle odoo methods, you need to send table of ids to the function declared outside of the class;

Example:

def multi_compute(ids)
kwargs = {'uid': request.uid, 'db': request.db}
with openerp.api.Environment.manage():
with openerp.registry(kwargs.get('db')).cursor() as new_cr:
env = openerp.api.Environment(new_cr, kwargs.get('uid'), {}) 
      playslip_obj = env['hr.payslip']
      payslip_ids = payslip_obj.browse(ids).compute_sheet()       

the call of the method with multiprocessing library should be like this:
list = list(split([slip for slip in slip_list_par], multiprocessing.cpu_count()))

try:
pool = multiprocessing.Pool(multiprocessing.cpu_count())
pool.map(multi_compute, list)
except KeyboardInterrupt, e:
pool.terminate()
raise e

if you get any connection problem add try and except to 'multi_compute' function 
and in the exception recall the method again ('multi_compute(ids)') cause sometimes it's blocked by postgress 
cause another process is blocking you process, so you need to recall it after a time

I hope this helps
                                                                                                                 
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
mar 17
4142
1
lut 24
96
2
gru 22
7927
1
kwi 21
5479
1
sty 20
4407