pyzmq

zmq send with NOBLOCK raise Resource temporarily unavailable

廉价感情. 提交于 2019-12-18 12:38:35
问题 This code will raise Resource temporarily unavailable when call with NOBLOCK: context = zmq.Context() sender = context.socket(zmq.PUSH) sender.bind('tcp://*:15556') sender.send('KeEpAliv', zmq.NOBLOCK) # this line will throw exception #sender.send('KeEpAliv') # this line will ok After read the docs, I found no hints for this. but docs for recv explained this flag. 回答1: Python wrappers raise zmq.error.Again if the underlying C API returns EAGAIN . Now, you should follow to zmq_send

ZeroMQ/ZMQ Push/Pull pattern usefulness

被刻印的时光 ゝ 提交于 2019-12-17 21:50:23
问题 In experimenting with the ZeroMQ Push/Pull (what they call Pipeline ) socket type, I'm having difficulty understanding the utility of this pattern. It's billed as a "load-balancer". Given a single server sending tasks to a number of workers, Push/Pull will evenly hand out the tasks between all the clients. 3 clients and 30 tasks, each client gets 10 tasks: client1 gets tasks 1, 4, 7,... client2, 2, 5,... and so on. Fair enough. Literally. However, in practice there is often a non-homogeneous

How can I use send_json with pyzmq PUB SUB

…衆ロ難τιáo~ 提交于 2019-12-13 12:20:45
问题 I need to send a dictionary as the message from a publisher to subscribers. With the REQ/REP pattern send_json and recv_json work nicely, but I can't seem to find an incantation that works for PUB/SUB. Hope it's not the case that PUB/SUB can only work with send() and recv(). Here's the listing for the experiment I put together: """ Experiments with 0MQ PUB/SUB pattern """ import os import sys import time import zmq from multiprocessing import Process from random import sample, choice import

Asyncio and pyzmq - 'utf-8' codec can't decode byte 0xff in position 0

让人想犯罪 __ 提交于 2019-12-13 03:45:30
问题 I have a asyncio server , which is an example from the TCP Doc. However I'm connecting to it using pyzmq and when the reader on the server tries to read I get a decode error. Any hint is highly appreciated. I've already tried encoding to utf-8 first, didn't help. Server: (Python 3.6) import asyncio async def handle_echo(reader, writer): data = await reader.read(100) print(data) message = data.decode() loop = asyncio.get_event_loop() coro = asyncio.start_server(handle_echo, '127.0.0.1', 5555,

ZeroMQ poll thread safety

為{幸葍}努か 提交于 2019-12-12 18:01:45
问题 I have a thread that is polling on a ZMQ Poller: poller.poll(timeout) This thread is also the one which receives and sends back messages over the sockets registered in the poller. Then I have another thread that may, eventually, create a new socket and register it for polling on input events: socket = context.socket(...) socket.bind/connect(...) poller.register(socket, zmq.POLLIN) Once the socket is registered, the latter thread will not touch it again. Is this safe? Update The answers

Multiprocessing vs gevent

百般思念 提交于 2019-12-12 11:35:34
问题 Currently I am using zeromq with pub-sub pattern, I have single worker to publish and many(8) subscriber (all will subscribe) to same pattern. Now I tried multiprocessing to spawn subscribers it works. I am missing few messages. Why I am using multiprocessing is to handle each message as it arrives and process them, every second publisher publishes 10 - 100 messages. In this case it is advised use multiprocessing or gevent ? 回答1: Multiprocessing will clearly have much higher memory overhead

Multithreading and ZMQ DEALER/REP hello world doesn't work

折月煮酒 提交于 2019-12-11 11:42:07
问题 First of all my code (largely inspired from ZMQ doc http://zguide.zeromq.org/py:mtserver): import zmq import time import sys import threading #SOCKET_NAME = "tcp://127.0.0.1:8000" SOCKET_NAME = "inproc://mysocket" def dealerRoutine(context): socket = context.socket(zmq.DEALER) socket.bind(SOCKET_NAME) time.sleep(12) socket.send("hello") socket.send("hello") print socket.recv() print socket.recv() socket.close() def workerRoutine(context): socket = context.socket(zmq.REP) socket.connect(SOCKET

Can't install PyZMP for Python — Dependencies

为君一笑 提交于 2019-12-11 09:19:57
问题 I am having trouble installing the PyZMP dependency for iPython. I have tried a number of things such as using pip/brew, but ended up installing the package manually using this answer. Now, pip list packages yields the following pyzmq (14.2.0-dev) pyzmq-static (2.2) (I have also tried using pyzmq-static). Also, my python eggs are clearly present in the proper location: ls /usr/local/lib/python2.7/site-packages/ | grep "pyzmq" pyzmq-14.2.0_dev-py2.7.egg-info pyzmq_static-2.2-py2.7.egg-info

How get redundancy for forwarder in ZMQ PUB/SUB?

坚强是说给别人听的谎言 提交于 2019-12-11 07:53:18
问题 I tried and made run this example. It worked very well. I can add as many publishers or subscribers as I want, everything will communicate thanks to the forwarder. My concern is about redundancy. If the forwarder does not respond anymore, nothing's gonna work until forwarder is up. I found an example for REQ/REP, but it can't be applied for PUB/SUB as subscribers. But idea is here. Is there a way to have something similar in a pub/sub scenario? Thank you. 回答1: First read this chapter. In the

ZeroMQ FiniteStateMachineException in REQ/REP pattern

六眼飞鱼酱① 提交于 2019-12-11 00:19:29
问题 I have two simple components which are supposed to communicate with each other using the REQ/REP ZeroMQ pattern. The Server (REP Socket) is implemented in Python using pyzmq: import zmq def launch_server(): print "Launching server" with zmq.Context.instance() as ctx: socket = ctx.socket(zmq.REP) socket.bind('tcp://127.0.0.1:5555') while True: msg = socket.recv() print "EOM\n\n" The Client (REQ socket) written in C# using the NetMQ library: using System; using System.Collections.Generic; using