On Mon, Jun 8, 2015 at 11:00 AM, Arnaud Loonstra <[email protected]> wrote:
> A python dictionary is not thread safe, AFAIK. So if multiple > producers(threads) write to the dictionary you'll run into trouble. > Depends what you mean. All of Python is threadsafe, thanks to the GIL. Since object IDs are unique as long as the objects exist, you should have no collisions putting different objects in the dictionary from different threads. You could also key by UUID if for some reason you have multiple threads sending the same exact object. -MinRK > > Rg, > > Arnaud > > On June 8, 2015 6:05:08 PM GMT+02:00, Min RK <[email protected]> wrote: > >> >> >> On Jun 8, 2015, at 01:35, Arnaud Loonstra <[email protected]> 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 >>> [email protected] >>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev >>> >> ------------------------------ >> >> zeromq-dev mailing list >> [email protected] >> http://lists.zeromq.org/mailman/listinfo/zeromq-dev >> >> > Send from my feature bloated phone. > > _______________________________________________ > zeromq-dev mailing list > [email protected] > http://lists.zeromq.org/mailman/listinfo/zeromq-dev > >
_______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
