0

simplified model like this: Execute init need time, Execute can not pickle when useing pool, so Execute must be initialized when using pool, each process needs to initialize an object, which will be very time-consuming. How to initialize the process pool first, and then transfer parameters?

import time
from multiprocessing import Pool

class Execute(object):
    def __init__(self):
        time.sleep(0.1)
        super(Execute, self).__init__()

    def func(self, i):
        time.sleep(0.08)
        print(i)


def func(i):
    model = Execute()
    model.func(i)


def use_pool():
    pool = Pool()
    for i in range(50):
        pool.apply_async(func, (i,))
    pool.close()
    pool.join()

like this

pool = Pool(4, func)
def use_pool():
    for i in range(50):
        pool.xxxx((i,))   # when use pool then transfer parameters
    pool.close()
    pool.join()
pluto
  • 21
  • 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 28 '22 at 13:08
  • https://stackoverflow.com/questions/72416594/typeerror-can-t-pickle-onnxruntime-capi-onnxruntime-pybind11-state-inferenceses – pluto May 28 '22 at 14:46

0 Answers0