[zeromq-dev] Client Server Model in Python
Robert Kern
robert.kern at gmail.com
Tue Aug 24 18:21:40 CEST 2010
On 8/24/10 8:17 AM, Martin Sustrik wrote:
> Abishek,
>
>> * I think the if the message processing logic takes lot of time, how
>> can I thread the process of processing the message (in Python)
>
> AFAIK Python does not provide real threads, just green threads. So the
> only option would be to run several python processes, connected to a
> single central queue device (zmq_queue).
Python does provide real OS threads. However, the interpreter has a Global
Interpreter Lock such that only one Python bytecode instruction runs at a time,
usually. The GIL is released during I/O and some other long computations done
inside C code that does not need to use the interpreter's data structures. Since
0MQ is running in its own thread and does not use the interpreter's data
structures, it does not grab hold of the GIL. The network I/O and the processing
already happen in separate threads. That's one of the nice things about using
pyzmq for networking over other Python solutions: you can write your processing
code very straightforwardly. You don't need to explicitly thread, either
coorperatively or preemptively, in order interleave your processing with your
networking.
That said, if the OP needs multiple processing threads for some reason, multiple
processes would be appropriate.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the zeromq-dev
mailing list