通过 dbus 传递大型数据结构
我正在使用 dbus 来通信两个程序。一个人创建一个大图像,然后将其发送给其他程序以进行进一步处理。我将图像作为 ByteArray 传递。
对于 2000x2000 图像,我的程序可以工作,但对于 4000x4000 图像,它会出现以下问题:
process 2283: arguments to dbus_message_iter_append_fixed_array() were
incorrect,assertion "n_elements <= DBUS_MAXIMUM_ARRAY_LENGTH / _dbus_type_get_alignment
(element_type)" failed in file dbus-message.c line 2628.
我知道这意味着我传递的数组大于允许的值。 dbus 中还有其他传递大数据结构的方法吗?
这是我正在使用的代码的摘录:
handle = StringIO()
# hdulist contains the large data structure
hdulist.writeto(handle)
hdub = dbus.ByteArray(handle.getvalue())
# this sends the image via dbus
self.dbi.store_image(hdub)
在另一端我有类似的东西
def store_image(self, bindata):
# Convert binary data back to HDUList
handle = StringIO.StringIO(bindata)
hdulist = pyfits.open(handle)
I'm using dbus to communicate two programs. One creates a large image and it later sends it other program for further processing. I'm passing the image as ByteArray.
With 2000x2000 images my program works, but with 4000x4000 it crasses with:
process 2283: arguments to dbus_message_iter_append_fixed_array() were
incorrect,assertion "n_elements <= DBUS_MAXIMUM_ARRAY_LENGTH / _dbus_type_get_alignment
(element_type)" failed in file dbus-message.c line 2628.
I understand that this means that I'm passing an array larger than allowed. Is there other way of passing large data strucutures in dbus?
This is an excerpt of the code I'm using:
handle = StringIO()
# hdulist contains the large data structure
hdulist.writeto(handle)
hdub = dbus.ByteArray(handle.getvalue())
# this sends the image via dbus
self.dbi.store_image(hdub)
In the other end I have something like
def store_image(self, bindata):
# Convert binary data back to HDUList
handle = StringIO.StringIO(bindata)
hdulist = pyfits.open(handle)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不认为 Dbus 确实是发送大量数据的最佳方式。
将数据结构写入 /tmp 中的文件,然后通过 dbus 在程序之间传递文件名怎么样?
I don't think Dbus is really the best way to send large amounts of data.
How about writing the data structure out to a file in /tmp, and just passing the filename between the programs via dbus instead?
D-bus 不会让您传递每条消息超过 128Mb 的数据,并且通常在
/etc/dbus-1/session.conf
中将限制设置为更低的值。命名管道就是什么你正在寻找。它就像一个临时文件,只不过数据不会写入磁盘,而是以非常低的开销从一个进程流式传输到另一个进程。它对数据大小没有限制。
请参阅 http://en.wikipedia.org/wiki/Named_pipe 和 在 Python 中创建临时 FIFO(命名管道)? 了解详细信息。
D-bus won't let you pass more than 128Mb of data per message, and the limit is usually set to even lower value in
/etc/dbus-1/session.conf
A named pipe is what you're looking for. It's like a temporary file except that the data is not written to disk, but streamed from one process to another with very low overhead. It has no limits on data size.
See http://en.wikipedia.org/wiki/Named_pipe and Create a temporary FIFO (named pipe) in Python? for details.
我现在想到的一个简单的解决方案是分离数据结构。将其分离,发送每个部分并将其在另一个程序上连接在一起。当然,需要注意一些以确保您正确加入。
One simple solution that comes to my mind right now is to separate the data structure.. Separate it, send each piece and join it together on the other program. Of course, some care would be necessary to assure that you would join it correctly.