[zeromq-dev] Passing a python object (PyZMQ)
Arnaud Loonstra
arnaud at sphaero.org
Mon Jun 8 20:00:37 CEST 2015
A python dictionary is not thread safe, AFAIK. So if multiple producers(threads) write to the dictionary you'll run into trouble.
Rg,
Arnaud
On June 8, 2015 6:05:08 PM GMT+02:00, Min RK <benjaminrk at gmail.com> wrote:
>
>
>> On Jun 8, 2015, at 01:35, Arnaud Loonstra <arnaud at sphaero.org> wrote:
>>
>>> On 06/06/2015 01:52 AM, MinRK wrote:
>>> Without using ctypes, you could pass the objects through a
>namespace:
>>>
>>> |# shared namespace
>>> ns = {}
>>>
>>> # sender
>>> ns[id(obj)] = obj
>>> pipe_out.send(struct.pack(b'Q',1))
>>>
>>> # receiver
>>> id_bytes = pipe_in.recv()
>>> obj_id = struct.unpack(b'Q', id_bytes)[0]
>>> obj = ns.pop(obj_id)
>>> |
>>>
>>> The ctypes cast approach doesn’t hold a reference to the object
>while
>>> it’s in transit, so it’s possible for the restoration to fail if the
>>> object has been garbage collected in between send/recv.
>>
>> You're right I ended up doing something very similar to workaround
>early
>> garbage collection but this is much nicer. However it only works
>between
>> a producer and consumer thread, not more. So every producer thread
>needs
>> its own namespace.
>
>I'm not sure why. You should only need one namespace per process.
>
>-MinRK
>
>>
>> Rg,
>>
>> Arnaud
>> --
>> w: http://www.sphaero.org
>> t: http://twitter.com/sphaero
>> g: http://github.com/sphaero
>> i: freenode: sphaero_z25
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>_______________________________________________
>zeromq-dev mailing list
>zeromq-dev at lists.zeromq.org
>http://lists.zeromq.org/mailman/listinfo/zeromq-dev
Send from my feature bloated phone.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20150608/68701e8e/attachment.htm>
More information about the zeromq-dev
mailing list