.. PyZMQ Bindings doc, by Min Ragan-Kelley, 2011
.. _bindings:
More Than Just Bindings
=======================
PyZMQ is ostensibly the Python bindings for `ØMQ`_, but the project, following
Python's 'batteries included' philosophy, provides more than just Python methods and
objects for calling into the ØMQ C++ library.
The Core as Bindings
--------------------
PyZMQ is currently broken up into four subpackages. First, is the Core. :mod:`zmq.core`
contains the actual bindings for ZeroMQ, and no extended functionality beyond the very
basic. The core modules are split, such that each basic ZeroMQ object (or function, if no
object is associated) is a separate module, e.g. :mod:`zmq.core.context` contains the
:class:`.Context` object, :mod:`zmq.core.poll` contains a :class:`.Poller` object, as well
as the :func:`.select` function, etc. ZMQ constants are, for convenience, all kept
together in :mod:`zmq.core.constants`.
There are two reasons for breaking the core into submodules: *recompilation* and
*derivative projects*. The monolithic PyZMQ became quite tedious to have to recompile
everything for a small change to a single object. With separate files, that's no longer
necessary. The second reason has to do with Cython. PyZMQ is written in Cython, a tool for
efficiently writing C-extensions for Python. By separating out our objects into individual
`pyx` files, each with their declarations in a `pxd` header, other projects can write
extensions in Cython and call directly to ZeroMQ at the C-level without the penalty of
going through our Python objects.
Core Extensions
---------------
We have extended the core functionality in two ways that appear inside the :mod:`core`
bindings, and are not general ØMQ features.
Builtin Serialization
*********************
First, we added common serialization with the builtin :py:mod:`json` and :py:mod:`pickle`
as first-class methods to the :class:`Socket` class. A socket has the methods
:meth:`~.Socket.send_json` and :meth:`~.Socket.send_pyobj`, which correspond to sending an
object over the wire after serializing with :mod:`json` and :mod:`pickle` respectively,
and any object sent via those methods can be reconstructed with the
:meth:`~.Socket.recv_json` and :meth:`~.Socket.recv_pyobj` methods. Unicode strings are
other objects that are not unambiguously sendable over the wire, so we include
:meth:`~.Socket.send_unicode` and :meth:`~.Socket.recv_unicode` that simply send via the
unambiguous utf-8 byte encoding. See :ref:`our Unicode discussion <unicode>` for more
information on the trials and tribulations of working with Unicode in a C extension while
supporting Python 2 and 3.
MessageTracker
**************
The second extension of basic ØMQ functionality is the :class:`MessageTracker`. The
MessageTracker is an object used to track when the underlying ZeroMQ is done with a
message buffer. One of the main use cases for ØMQ in Python is the ability to perform
non-copying sends. Thanks to Python's buffer interface, many objects (including NumPy
arrays) provide the buffer interface, and are thus directly sendable. However, as with any
asynchronous non-copying messaging system like ØMQ or MPI, it can be important to know
when the message has actually been sent, so it is safe again to edit the buffer without
worry of corrupting the message. This is what the MessageTracker is for.
The MessageTracker is a simple object, but there is a penalty to its use. Since by its
very nature, the MessageTracker must involve threadsafe communication (specifically a
builtin :py:class:`~Queue.Queue` object), instantiating a MessageTracker takes a modest
amount of time (10s of µs), so in situations instantiating many small messages, this can
actually dominate performance. As a result, tracking is optional, via the ``track`` flag,
which is optionally passed, always defaulting to ``False``, in each of the three places
where a Message is instantiated: The :class:`.Message` constructor, and non-copying sends
and receives.
A MessageTracker is very simple, and has just one method and one attribute. The property
:attr:`MessageTracker.done` will be ``True`` when the Message(s) being tracked are no
longer in use by ØMQ, and :meth:`.MessageTracker.wait` will block, waiting for the
Message(s) to be released.
.. Note::
A message cannot be tracked after it has been instantiated without tracking. If a
Message is to even have the *option* of tracking, it must be constructed with
``track=True``.
Extensions
----------
So far, PyZMQ includes three extensions to core ØMQ that we found basic enough to be
included in PyZMQ itself:
* :ref:`zmq.log <logging>` : Logging handlers for hooking Python logging up to the
network
* :ref:`zmq.devices <devices>` : Custom devices and objects for running devices in the
background
* :ref:`zmq.eventloop <eventloop>` : The `Tornado`_ event loop, adapted for use
with ØMQ sockets.
.. _ØMQ: http://www.zeromq.org
.. _Tornado: https://github.com/facebook/tornado
没有合适的资源?快使用搜索试试~ 我知道了~
pyzmq-2.1.1.tar.gz
0 下载量 104 浏览量
2024-06-09
22:41:33
上传
评论
收藏 1.35MB GZ 举报
温馨提示
Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
资源推荐
资源详情
资源评论
收起资源包目录
pyzmq-2.1.1.tar.gz (314个子文件)
make.bat 3KB
.buildinfo 230B
.buildinfo 230B
socket.c 427KB
message.c 283KB
poll.c 179KB
monitoredqueue.c 172KB
constants.c 116KB
context.c 102KB
error.c 78KB
stopwatch.c 73KB
device.c 64KB
version.c 53KB
initthreads.c 42KB
default.css 9KB
default.css 9KB
default.css 9KB
basic.css 8KB
basic.css 8KB
pygments.css 4KB
pygments.css 4KB
zmq.core.socket.doctree 115KB
zmq.devices.monitoredqueuedevice.doctree 104KB
zmq.devices.basedevice.doctree 97KB
zmq.log.handlers.doctree 86KB
zmq.eventloop.zmqstream.doctree 65KB
unicode.doctree 61KB
zmq.eventloop.ioloop.doctree 57KB
pyversions.doctree 51KB
zmq.core.message.doctree 42KB
morethanbindings.doctree 35KB
zmq.core.error.doctree 34KB
zmq.core.poll.doctree 32KB
devices.doctree 23KB
logging.doctree 20KB
eventloop.doctree 20KB
zmq.eventloop.stack_context.doctree 17KB
zmq.core.context.doctree 17KB
index.doctree 17KB
zmq.devices.monitoredqueue.doctree 15KB
zmq.core.stopwatch.doctree 14KB
zmq.utils.jsonapi.doctree 12KB
zmq.core.device.doctree 9KB
gen.doctree 9KB
zmq.core.version.doctree 8KB
zmq.doctree 6KB
index.doctree 6KB
zmq.utils.initthreads.doctree 6KB
pyversion_compat.h 2KB
zmq_compat.h 900B
allocate.h 883B
._pyversion_compat.h 186B
._zmq_compat.h 184B
genindex.html 48KB
genindex.html 48KB
zmq.core.socket.html 30KB
zmq.core.socket.html 30KB
zmq.devices.monitoredqueuedevice.html 29KB
zmq.devices.monitoredqueuedevice.html 29KB
zmq.devices.basedevice.html 27KB
zmq.devices.basedevice.html 27KB
zmq.log.handlers.html 26KB
zmq.log.handlers.html 26KB
zmq.eventloop.ioloop.html 22KB
zmq.eventloop.ioloop.html 22KB
pyversions.html 21KB
pyversions.html 21KB
unicode.html 20KB
unicode.html 20KB
zmq.eventloop.zmqstream.html 19KB
zmq.eventloop.zmqstream.html 19KB
index.html 17KB
index.html 17KB
morethanbindings.html 15KB
morethanbindings.html 15KB
zmq.core.message.html 15KB
zmq.core.message.html 15KB
devices.html 14KB
devices.html 14KB
zmq.core.error.html 14KB
zmq.core.error.html 14KB
logging.html 13KB
logging.html 13KB
eventloop.html 13KB
eventloop.html 13KB
index.html 13KB
index.html 13KB
zmq.core.poll.html 12KB
zmq.core.poll.html 12KB
zmq.eventloop.stack_context.html 10KB
zmq.eventloop.stack_context.html 10KB
zmq.core.context.html 9KB
zmq.core.context.html 9KB
zmq.devices.monitoredqueue.html 8KB
zmq.devices.monitoredqueue.html 8KB
py-modindex.html 8KB
py-modindex.html 8KB
zmq.core.stopwatch.html 8KB
zmq.core.stopwatch.html 8KB
zmq.utils.jsonapi.html 7KB
共 314 条
- 1
- 2
- 3
- 4
资源评论
程序员Chino的日记
- 粉丝: 3643
- 资源: 5万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功