[zeromq-dev] Fwd: Re: New Python bindings
Jon Dyte
jon at totient.co.uk
Mon Feb 15 11:22:22 CET 2010
On Monday 15 Feb 2010, you wrote:
> Jon Dyte wrote:
>
> > On the other hand it might be cheaper to just take the hit of the copy,
as
> > using the ref count and free function, means the io thread would end up
> > calling into the python runtime, which might slow things down more and
> > possibly cause other threading issues.
>
> Right. However, it depends on the Python runtime. Would it survive being
> called from two different threads? If not so, making a copy of the
> message is much more efficient than wrapping each call in a mutex.
>
> Martin
>
Python runtime has one big lock called the GIL(global-interpreter-lock).
This means that python only really runs one python thread(ie started from
python code ) at a time
(some might say that's not threaded at all ;-) ) and they get some sort of
timeslice(number of byte code instructions?) before yielding.
Note: AFAIK Jython and IronPython (JVM and .Net) threads work more as
expected.
When writing a c-module extension calling into a foreign interface, you can
release the GIL.
The io-thread will have to acquire GIL in order to free it up.
So in this case on balance I'd think I would take the hit of the copy.
Jon
More information about the zeromq-dev
mailing list