Answers for "typeerror: cannot pickle 'weakref' object"

0

typeerror: cannot pickle 'weakref' object

Solution 1

Set foo.process_1 to None or something else. Or store the Processes somewhere else than in foo to prevent being passed when starting process_2.

...
def do_multiprocessing(self):
    self.process_1.start()
    self.process_1 = None # Remove exited process
    self.process_2.start()
...
Solution 2

Remove the problematic variable (process_1) from pickling:

class Foo:
    def __getstate__(self):
        # capture what is normally pickled
        state = self.__dict__.copy()

        # remove unpicklable/problematic variables 
        state['process_1'] = None
        return state
...
Posted by: Guest on February-03-2022

Code answers related to "typeerror: cannot pickle 'weakref' object"

Browse Popular Code Answers by Language