Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does 'Frame' object support buffer interface? #719

Closed
liuyangc3 opened this issue Sep 6, 2015 · 2 comments
Closed

does 'Frame' object support buffer interface? #719

liuyangc3 opened this issue Sep 6, 2015 · 2 comments

Comments

@liuyangc3
Copy link

Hi,

I am using zerorpc with Python2.6 on a CentOS 6.5
I just followed the http://www.zerorpc.io/ demo and the server side got this

Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/zerorpc/channel.py", line 79, in _channel_dispatcher
    event = self._events.recv()
  File "/usr/lib/python2.6/site-packages/zerorpc/events.py", line 332, in recv
    event = Event.unpack(blob)
  File "/usr/lib/python2.6/site-packages/zerorpc/events.py", line 188, in unpack
    unpacker.feed(blob)
  File "msgpack/_unpacker.pyx", line 318, in msgpack._unpacker.Unpacker.feed (msgpack/_unpacker.cpp:318)
TypeError: 'Frame' does not have the buffer interface

zerorpc use msgpack to serialize object , and , debug from IDE , found that the argument blob in unpacker.feed(blob) is class 'zmq.sugar.frame.Frame'
here is the msgpack feed() function
https://github.com/msgpack/msgpack-python/blob/master/msgpack/_unpacker.pyx#L318

def feed(self, object next_bytes):
    PyObject_GetBuffer(next_bytes, &pybuff, PyBUF_SIMPLE)

it use a C API get buffer from object

and here is what I found in /usr/lib64/python2.6/site-packages/zmq/backend/cython/message.pxd

cdef class Frame:

    cdef zmq_msg_t zmq_msg
    cdef object _data      # The actual message data as a Python object.
    cdef object _buffer    # A Python Buffer/View of the message contents
...
    cdef object _getbuffer(self) # Construct self._buffer.

seems that Frame object supoort Python Buffer interface

I am confused why feed() failed in getting buffer? Can anyone explan it?

Python 2.6.6
pyzmq 14.7.0
libzmq 4.1.2

Thanks.

@minrk
Copy link
Member

minrk commented Sep 7, 2015

@liuyangc3 Frame does provide the buffer interface. Here's a test script:

import sys
import zmq
import msgpack

print(sys.version)
print("libzmq-%s" % zmq.zmq_version())
print("pyzmq-%s" % zmq.pyzmq_version())
print("msgpack-%s" % ('.'.join(map(str, msgpack.version))))

ctx = zmq.Context.instance()
a = ctx.socket(zmq.PAIR)
a.bind('inproc://a')
b = ctx.socket(zmq.PAIR)
b.connect('inproc://a')

d = {'a': 5}
a.send(msgpack.packb(d))

frame = b.recv(copy=False)
print("Trying msgpack.unpackb on %r" % frame)

d2 = msgpack.unpackb(frame)
assert d2 == d, "Failed"
print("Success")

Which gives:

2.6.9 |Continuum Analytics, Inc.| (unknown, Jan 10 2014, 13:33:57) 
[GCC 4.2.1 (Apple Inc. build 5577)]
libzmq-4.0.5
pyzmq-14.7.0
msgpack-0.4.6
Trying msgpack.unpackb on <zmq.sugar.frame.Frame object at 0x10056b910>
Success

for me

@kirienko
Copy link

@minrk your test script works with ipython, but not with pypy:

$ ipython test.py 
2.7.5 (default, Jun 24 2015, 00:41:19) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)]
libzmq-3.2.5
pyzmq-14.3.1
msgpack-0.4.7
Trying msgpack.unpackb on <zmq.backend.cython.message.Frame object at 0x25d0dd0>
Success

For pypy (everything was installed with pypy -m pip install <package>):

$ pypy test.py 
2.7.10 (bbd45126bc691f669c4ebdfbd74456cd274c6b92, Jun 30 2016, 15:15:02)
[PyPy 5.0.1 with GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
libzmq-4.1.5
pyzmq-15.3.0
msgpack-0.4.7
Trying msgpack.unpackb on <zmq.backend.cffi.message.Frame object at 0x00007f994dc602c0>
Traceback (most recent call last):
  File "test.py", line 22, in <module>
    d2 = msgpack.unpackb(frame)
  File "/usr/lib64/pypy-5.0.1/site-packages/msgpack/fallback.py", line 96, in unpackb
    ret = unpacker._fb_unpack()
  File "/usr/lib64/pypy-5.0.1/site-packages/msgpack/fallback.py", line 498, in _fb_unpack
    typ, n, obj = self._read_header(execute, write_bytes)
  File "/usr/lib64/pypy-5.0.1/site-packages/msgpack/fallback.py", line 346, in _read_header
    c = self._fb_read(1, write_bytes)
  File "/usr/lib64/pypy-5.0.1/site-packages/msgpack/fallback.py", line 312, in _fb_read
    return buffs[self._fb_buf_i][self._fb_buf_o - n:self._fb_buf_o]
TypeError: 'Frame' object is not subscriptable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants