Skip to content

Allow Pyav objects to be serialized by pickle #652

@vtexier

Description

@vtexier

Overview

Be able to serialize/de-serialize Pyav objects with pickle.

Pickle raise an error, complaining about __reduce__ magic function to be implemented.

pickle.dumps(packet)
  File "stringsource", line 2, in av.packet.Packet.__reduce_cython__
TypeError: no default __reduce__ due to non-trivial __cinit__

Desired Behavior

Pyav objects should be able to be serialized/de-serialized with pickle.

Example API

# pickle an av.packet.Packet instance
pickled = pickle.dumps(mypacket)

# get back packet instance
unpickled = pickle.loads(pickled)

To achieve that, it seems that there is a decorator in Cython since 0.26.

@cython.auto_pickle(True)

http://blog.behnel.de/posts/whats-new-in-cython-026.html

https://stackoverflow.com/questions/12646436/pickle-cython-class

Additional context

I am trying to use Pyav on Apache Spark, to distribute encoding across servers.

Pyspark (Python implementation of Spark) use pickle to transfer code object instances to servers.

So, making Pyav classes pickabled will allow to distribute Pyav jobs on a farm of servers, with pyspark or other similar tools.

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