python cPickle.PicklingError: Can't pickle <type 'instancemethod'> .I know the reason, but I don't know how to solve it

Issue #938 wontfix
created an issue
    from multiprocessing import Pool
    import openpyxl

    def proxy(cls_instance, index):
        return cls_instance.func(index)

    class Runner(object):
        def __init__(self, obtest, sheet):
            self.obtest = obtest
            self.sheet = sheet

        def func(self, index):
            return index

    class OBTest(object):

        def run(self):
            wb = openpyxl.load_workbook('/Users/attackt/Downloads/excelfile.xlsx')
            pool = Pool(processes=5)
            sheets = wb.worksheets
            # sheets = ['A', 'B', 'C', 'D']
            result = []
            for index, sheet in enumerate(sheets):
                instance = Runner(self, sheet)
                result.append(pool.apply_async(proxy, (instance, index)))

            for data in result:
                print data.get()

    if __name__ == '__main__':

Comments (8)

  1. loopbing reporter

    None, True, and False
    integers, long integers, floating point numbers, complex numbers
    normal and Unicode strings
    tuples, lists, sets, and dictionaries containing only picklable objects
    functions defined at the top level of a module
    built-in functions defined at the top level of a module
    classes that are defined at the top level of a module
    instances of such classes whose dict or the result of calling
    getstate() is picklable (see section The pickle protocol for details).

  2. loopbing reporter

    I need to collect all the cell information. When I get the sheets collection, I need a lot of process. Each process can parse a sheet independently and then summarize it.

  3. Log in to comment