Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python GRPC Client issues with BMV2 #287

Closed
b3n-l opened this issue Jan 23, 2018 · 2 comments
Closed

Python GRPC Client issues with BMV2 #287

b3n-l opened this issue Jan 23, 2018 · 2 comments

Comments

@b3n-l
Copy link

b3n-l commented Jan 23, 2018

Hi all,

I appear to be having issues with the GRPC client in Python with the latest updates.
PI is built with ./configure --with-bmv2 --with-proto --with-cli --with-sysrepo and the python libraries generated have been installed on the host.

The code I'm using is as follows:

channel = grpc.insecure_channel('localhost:50051')

client_stub = p4runtime_pb2.P4RuntimeStub(channel)

# Create stream message request
stream_message_request = p4runtime_pb2.StreamMessageRequest()
arb = stream_message_request.arbitration
arb.device_id = 1

election_id = p4runtime_pb2.Uint128()
election_id.high = 0
election_id.low = 1

arb.election_id.CopyFrom(election_id)
stream = client_stub.StreamChannel(stream_message_request)

The error message I get is:

ERROR:root:Exception iterating requests!
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/grpc/_channel.py", line 184, in consume_request_iterator
    request = next(request_iterator)
TypeError: StreamMessageRequest object is not an iterator

Is there somewhere I'm going wrong, or is there a fault in the way the code is being generated? I've tried rebuilding on 2 machines, both on Ubuntu 16.04LTS with latest updates applied

@antoninbas
Copy link
Member

This is not how the gRPC client API works for bi-directional streams (see https://grpc.io/docs/tutorials/basic/python.html). The StreamChannel method takes an iterator as a parameter and returns an iterator.

You can use something like this:

def request():
  yield stream_message_request

for response in client_stub.StreamChannel(request()):
  print response

However this won't work in this specific case because the StreamChannel stream on which you send the arbitration method is supposed to stay open while you send Write RPC requests. See here for a working example: https://github.com/p4lang/PI/blob/master/proto/ptf/base_test.py#L230. I used Python thread-safe queues to store requests and responses and I created a new thread to wait for responses.

@b3n-l
Copy link
Author

b3n-l commented Jan 29, 2018

Closing as it was down to my errors. Working now, thanks for your help.

@b3n-l b3n-l closed this as completed Jan 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants