Skip to content

make world picklable #22

@sbarthelemy

Description

@sbarthelemy

Here is an example of WorldObserver that tries to pickle world at each simulation timestep

#import cPickle as pickle
import pickle

class WorldPickler(WorldObserver):
    def __init__(self, world, file):
        self._file = open(file, 'wb')
        self._dumps = []
        self._world = world

    def init(self):
        pass

    def update(self, dt):
        world = self._world
        self._dumps.append(cPickle.dumps(world, protocol=-1))

    def finish(self):
        pickle.dump(self._dumps, self._file, protocol=-1)

However, it fails with this error:

pickle.PicklingError: Can't pickle <type 'instancemethod'>: it's not found as __builtin__.instancemethod

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions