cloudpipe / cloudpickle

Extended pickling support for Python objects
Other
1.64k stars 167 forks source link

Issue with pickling an unpickled object #476

Open fl8k opened 2 years ago

fl8k commented 2 years ago

Python 3.9.6 | cloudpickle 2.0.0 While using cloudpickle to pack some classes, I encountered the following error: \lib\dis.py", line 347, in _get_instructions_bytes argval = cmp_op[arg] IndexError: tuple index out of range arg = 6 op = 107

Here is the segment of code (a class method) it was processing when the error occurred:

def startTimer(self,name):  
    if name in self.timers and not self.timers[name]['start'] is None:
        if self.timers[name]['stop'] is None:
            print(f"Timer ({name}) has already been started..")
            return 
        else:
            print(f"Timer ({name}) being restarted from last stop ({self.timers[name]['stop']})")
    self.timers[name]={"start":time(),"stop":None}

Here is the bytecode:

b't\x00d\x01d\x02\x8d\x01|\x00_\x01d\x03g\x01|\x00_\x02d\x04|\x00_\x03g\x00|\x00_\x04d\x00|\x00_\x05|\x01|\x00_\x06|\x00\xa0\x07\xa1\x00\x01\x00t\x08|\x00j\x01\x83\x01\x01\x00d\x00S\x00'

Here is the unpacked code:

[(0, 116, 0), (2, 100, 1), (4, 100, 2), (6, 141, 1), (8, 124, 0), (10, 95, 1), (12, 100, 3), (14, 103, 1), (16, 124, 0), (18, 95, 2), (20, 100, 4), (22, 124, 0), (24, 95, 3), (26, 103, 0), (28, 124, 0), (30, 95, 4), (32, 100, 0), (34, 124, 0), (36, 95, 5), (38, 124, 1), (40, 124, 0), (42, 95, 6), (44, 124, 0), (46, 160, 7), (48, 161, 0), (50, 1, None), (52, 116, 8), (54, 124, 0), (56, 106, 1), (58, 131, 1), (60, 1, None), (62, 100, 0), (64, 83, None)]

This is happening when I try to re-cloudpickle an object that was already pickled and loaded with cloudpickle. The original pickling goes through fine, I am able to unpack it without issues, but when I try to re-pickle the unpacked object again I get the above error.

ogrisel commented 2 years ago

Could you please craft a minimal reproducing example that preferably does not depend on any third party library?