Skip to content

Can PyCapsule be pickled? #354

@mmckerns

Description

@mmckerns

Easy way to produce a PyCapsule object:

Python 3.6.10 (default, Dec 21 2019, 11:39:07) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dill
>>> import ctypes
>>> pycapsule = ctypes.pythonapi.PyCapsule_New
>>> pycapsule.restype = ctypes.py_object
>>> c = pycapsule()
>>> c   
\ufffd" at 0x1040f2330>d\ufffdtcH\ufffd
>>> type(c)
<class 'PyCapsule'>
>>> dill.dumps(c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mmckerns/lib/python3.6/site-packages/dill-0.3.2.dev0-py3.6.egg/dill/_dill.py", line 265, in dumps
    dump(obj, file, protocol, byref, fmode, recurse, **kwds)#, strictio)
  File "/Users/mmckerns/lib/python3.6/site-packages/dill-0.3.2.dev0-py3.6.egg/dill/_dill.py", line 259, in dump
    Pickler(file, protocol, **_kwds).dump(obj)
  File "/Users/mmckerns/lib/python3.6/site-packages/dill-0.3.2.dev0-py3.6.egg/dill/_dill.py", line 445, in dump
    StockPickler.dump(self, obj)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pickle.py", line 409, in dump
    self.save(obj)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pickle.py", line 496, in save
    rv = reduce(self.proto)
TypeError: can't pickle PyCapsule objects

Interface is here: https://github.com/python/cpython/blob/master/Include/pycapsule.h

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions