Protobuf messages are thread-compatible. You can read a protobuf message 
concurrently in multiple threads. But if you need to update it at the same 
time, all threads must acquire a lock before accessing or updating the 
message.

On Tuesday, January 15, 2013 7:45:35 PM UTC+8, Johannes Wienke wrote:
>
> Hi,
>
> I couldn't find any information about whether the python generated classes 
> are thread-safe, or can at least be used for read-only purposes by several 
> threads in parallel. Is anything known about that?
>
> The reason I am asking is that we receive an exception in one of our 
> systems where actually two threads are operating on a message in parallel. 
> One prints out the whole message and the other one reads some attributes 
> from the message. The printing thread consistently crashes with the 
> following backtrace:
>
>   File 
> "/vol/humavips/releases/y3demo/lib/python2.7/site-packages/rsb_python-0.7.0-py2.7.egg/rsb/util.py",
>  line 252, in push
>     self.__logger.debug("Got new message to dispatch: %s" % message)
>   File 
> "/vol/humavips/releases/y3demo/lib/python2.7/site-packages/rsb_python-0.7.0-py2.7.egg/rsb/__init__.py",
>  line 1068, in __str__
>     % ("Event", self.__id, self.__scope, printData, self.__type, 
> self.__metaData, self.__causes)
>   File 
> "/usr/lib/python2.7/dist-packages/google/protobuf/internal/python_message.py",
>  line 660, in __str__
>     return text_format.MessageToString(self)
>   File "/usr/lib/python2.7/dist-packages/google/protobuf/text_format.py", 
> line 58, in MessageToString
>     PrintMessage(message, out, as_utf8=as_utf8, as_one_line=as_one_line)
>   File "/usr/lib/python2.7/dist-packages/google/protobuf/text_format.py", 
> line 67, in PrintMessage
>     for field, value in message.ListFields():
>   File 
> "/usr/lib/python2.7/dist-packages/google/protobuf/internal/python_message.py",
>  line 554, in ListFields
>     all_fields = [item for item in self._fields.iteritems() if 
> _IsPresent(item)]
> RuntimeError: dictionary changed size during iteration
>
>
> Would be nice if someone could point out the exact threading guarantees of 
> the python API.
>
> Kind regards,
> Johannes
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/KVRYLPZ0knsJ.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to