Re: [grpc-io] Safe to modify message object after yielded to a request/response stream? (Python)
Thanks a lot for responding Nathaniel. In honesty the use case is very slight simplification to a utility generator function. The difference is only a couple of lines, and arguably it would be clearer to explicitly create a new request each time anyway. As you don't guarantee this behaviour, even if a change is very unlikely, I'll just go for the safe option. Sorry to piggyback something else: I often send binary data and associated metadata together over gRPC. The utility function in question is to chunk the binary data into a request stream while including the metadata in the first request of the stream. It's a pity that gRPC doesn't do something like this built-in. I appreciate it's hard given the separation between gRPC and protobuf, but I think a slightly leaky API that takes both a protobuf and a binary payload (or a named list of binary payloads) would be a reasonable compromise. In Python this could even use the buffer protocol for near-C++ efficiency (imagine: here's my protobuf and some numpy arrays). I notice that TensorFlow solves this problem by having a load of custom gRPC code (which I don't understand to be honest!), which I think shows a gap in gRPC's API. But I'm not paying for gRPC, so who am I to complain :=) On Thursday, March 29, 2018 at 2:24:38 PM UTC+1, Nathaniel Manista wrote: > > This happens to be the case today... > ... but I don't think it's something that we want to guarantee. What's > going on in your use case that has you wanting to clear and reuse the same > message rather than just create and yield a new one each time? > -Nathaniel > -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscr...@googlegroups.com. To post to this group, send email to grpc-io@googlegroups.com. Visit this group at https://groups.google.com/group/grpc-io. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/035da6c1-717b-443c-815f-3be8ae777287%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[grpc-io] Re: Safe to modify message object after yielded to a request/response stream? (Python)
Follow up: Would the answer be any different if I was using the non-blocking API: request_iter = my_iter(RequestType(), data) response_future = my_stub.streaming_request.future(request_iter) -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscr...@googlegroups.com. To post to this group, send email to grpc-io@googlegroups.com. Visit this group at https://groups.google.com/group/grpc-io. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/cf6dc7b2-1d49-429d-b660-e919535c6f3b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[grpc-io] Safe to modify message object after yielded to a request/response stream? (Python)
Consider the following snippet: def my_iter(some_request, extra_data_list): for item in extra_data_list: some_request.extra = item yield some_request some_request.Clear() # ... some time later ... response = my_stub.streaming_request(my_iter(RequestType(), data)) My question is: Is this safe? My concern is that the yielded request message object could be sent off to another thread for serialisation, but my code could mutate it (to create the next item in the stream) before it gets there. I suspect that the yielded message is serialised to bytes before the iterator is allowed to continue, which would mean that this is actually safe. But I'd like to be sure that's what's happening, and is guaranteed. Many thanks! -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscr...@googlegroups.com. To post to this group, send email to grpc-io@googlegroups.com. Visit this group at https://groups.google.com/group/grpc-io. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/00d348db-4390-45cc-998c-cb7e94434035%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.