Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/takluyver/zantedeschia
Experimental ZMQ integration with asyncio
https://github.com/takluyver/zantedeschia
Last synced: 4 days ago
JSON representation
Experimental ZMQ integration with asyncio
- Host: GitHub
- URL: https://github.com/takluyver/zantedeschia
- Owner: takluyver
- Created: 2015-02-06T23:34:16.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-02-09T01:30:08.000Z (almost 10 years ago)
- Last Synced: 2024-12-05T13:06:19.710Z (21 days ago)
- Language: Python
- Size: 137 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
Zantedeschia is an experimental alternative integration between asyncio and
ZeroMQ sockets.I started trying to use `aiozmq `_, but I
objected to some of the design decisions. I borrowed ideas from that code, but
did a few things differently:1. ``aiozmq`` is built around asyncio's protocol and transport APIs, which I
find hard to use; even the simplest examples involve subclassing
``ZmqProtocol``. Zantedeschia uses a single AsyncZMQSocket wrapper class,
with simple semantics.
2. Zantedeschia does not include an RPC framework.
3. Zantedeschia expects the user to create and connect ZMQ sockets using PyZMQ,
then wrap them in an AsyncZMQSocket object.*Zantedeschia* is a genus of flowers. Asyncio itself was originally codenamed
'tulip', and a tradition developed of naming asyncio libraries after flowers.Use this at your own risk. MinRK, the author of PyZMQ, told me that I definitely
shouldn't rely on the ZMQ file descriptors for an event loop, but I'm doing
exactly that.Ping server example:
.. code:: python
import asyncio, zmq, zantedeschia
ctx = zmq.Context()
s = ctx.socket(zmq.REP)
s.bind('tcp://127.0.0.1:8123')
async_sock = zantedeschia.AsyncZMQSocket(s)def pong():
while True:
msg_parts = yield from async_sock.recv_multipart()
yield from async_sock.send_multipart(msg_parts)asyncio.get_event_loop().run_until_complete(pong())
Using the ``on_recv`` API instead:
.. code:: python
import asyncio, zmq, zantedeschia
ctx = zmq.Context()
s = ctx.socket(zmq.REP)
s.bind('tcp://127.0.0.1:8123')
async_sock = zantedeschia.AsyncZMQSocket(s)@async_sock.on_recv
def pong(msg_parts):
async_sock.send_multipart(msg_parts)asyncio.get_event_loop().run_forever()