Skip to content

Support for pickling functions within a class defined outside of __main__? #175

@mlucas-NU

Description

@mlucas-NU

Cloudpickle's ability to serialize instantiated classes and their member functions is a huge advantage over cloudpickle alternatives. Unfortunately, this feature seems limited heavily to the check for instantiated_class.__module__ == '__main__'.

One hacky solution is to set __module__ in the class definition:

class SomeFunClass(object):
    __module__ = '__main__'

    # Rest of the class definition

But this could cause problems with any code that relies on a proper value for __module__. Is there another solution I'm not seeing?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions