[zeromq-dev] Client Server Model in Python
Oliver Smith
oliver at kfs.org
Tue Aug 24 19:39:30 CEST 2010
Oliver Smith said the following on 8/24/2010 12:29 PM:
> Abhishek K said the following on 8/24/2010 12:00 PM:
>> The method I was looking for was
>>
>> class Extended_thread(Threading.thread):
>> def run(a)
>> #some logic
>>
>> context=zmq.Context()
>> socket=context.socket(zmq.REP)
>> socket.bind('tcp://127.0.0.1:5555 <http://127.0.0.1:5555/>')
>> while True:
>> message=socket.recv()
>> new Extended_thread(socket)
>
> Wait - that's creating a new thread for every message you receive.
> That's going to be incredibly expensive.
What you actually need, apparently, is a zmq_device. I'm not sure how
you do that in Python.
Again, I think this is another example for the case where it should be
allowed to bind multiple times to an address over the same context, so
that multiple threads can service a single port, e.g.
ctx = zmq.Context(1)
workers = []
def createThreads(numThreads, endpoint):
global ctx, workers
for i in range(0, numThreads):
sock = ctx.socket(zmq.REP)
sock.bind(endpoint)
thread = new Extended_thread(sock)
workers.append(thread)
You can do this with a device, but if you're going to be doing it all
over a single context, it just seems like so much cpu wastage :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20100824/47d5fa6f/attachment.htm>
More information about the zeromq-dev
mailing list