Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
4df39871
Commit
4df39871
authored
9 years ago
by
Leifur Halldor Asgeirsson
Browse files
Options
Downloads
Patches
Plain Diff
python3-compatible syntax for python examples
parent
79787471
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/python/helloworld/greeter_client.py
+4
-2
4 additions, 2 deletions
examples/python/helloworld/greeter_client.py
examples/python/route_guide/route_guide_client.py
+19
-17
19 additions, 17 deletions
examples/python/route_guide/route_guide_client.py
with
23 additions
and
19 deletions
examples/python/helloworld/greeter_client.py
+
4
−
2
View file @
4df39871
# Copyright 2015, Google Inc.
# Copyright 2015
-2016
, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
...
...
@@ -29,6 +29,8 @@
"""
The Python implementation of the GRPC helloworld.Greeter client.
"""
from
__future__
import
print_function
from
grpc.beta
import
implementations
import
helloworld_pb2
...
...
@@ -40,7 +42,7 @@ def run():
channel
=
implementations
.
insecure_channel
(
'
localhost
'
,
50051
)
stub
=
helloworld_pb2
.
beta_create_Greeter_stub
(
channel
)
response
=
stub
.
SayHello
(
helloworld_pb2
.
HelloRequest
(
name
=
'
you
'
),
_TIMEOUT_SECONDS
)
print
"
Greeter client received:
"
+
response
.
message
print
(
"
Greeter client received:
"
+
response
.
message
)
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
examples/python/route_guide/route_guide_client.py
+
19
−
17
View file @
4df39871
# Copyright 2015, Google Inc.
# Copyright 2015
-2016
, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
...
...
@@ -29,6 +29,8 @@
"""
The Python implementation of the gRPC route guide client.
"""
from
__future__
import
print_function
import
random
import
time
...
...
@@ -49,13 +51,13 @@ def make_route_note(message, latitude, longitude):
def
guide_get_one_feature
(
stub
,
point
):
feature
=
stub
.
GetFeature
(
point
,
_TIMEOUT_SECONDS
)
if
not
feature
.
location
:
print
"
Server returned incomplete feature
"
print
(
"
Server returned incomplete feature
"
)
return
if
feature
.
name
:
print
"
Feature called %s at %s
"
%
(
feature
.
name
,
feature
.
location
)
print
(
"
Feature called %s at %s
"
%
(
feature
.
name
,
feature
.
location
)
)
else
:
print
"
Found no feature at %s
"
%
feature
.
location
print
(
"
Found no feature at %s
"
%
feature
.
location
)
def
guide_get_feature
(
stub
):
...
...
@@ -69,18 +71,18 @@ def guide_list_features(stub):
latitude
=
400000000
,
longitude
=
-
750000000
),
hi
=
route_guide_pb2
.
Point
(
latitude
=
420000000
,
longitude
=
-
730000000
))
print
"
Looking for features between 40, -75 and 42, -73
"
print
(
"
Looking for features between 40, -75 and 42, -73
"
)
features
=
stub
.
ListFeatures
(
rect
,
_TIMEOUT_SECONDS
)
for
feature
in
features
:
print
"
Feature called %s at %s
"
%
(
feature
.
name
,
feature
.
location
)
print
(
"
Feature called %s at %s
"
%
(
feature
.
name
,
feature
.
location
)
)
def
generate_route
(
feature_list
):
for
_
in
range
(
0
,
10
):
random_feature
=
feature_list
[
random
.
randint
(
0
,
len
(
feature_list
)
-
1
)]
print
"
Visiting point %s
"
%
random_feature
.
location
print
(
"
Visiting point %s
"
%
random_feature
.
location
)
yield
random_feature
.
location
time
.
sleep
(
random
.
uniform
(
0.5
,
1.5
))
...
...
@@ -90,10 +92,10 @@ def guide_record_route(stub):
route_iter
=
generate_route
(
feature_list
)
route_summary
=
stub
.
RecordRoute
(
route_iter
,
_TIMEOUT_SECONDS
)
print
"
Finished trip with %s points
"
%
route_summary
.
point_count
print
"
Passed %s features
"
%
route_summary
.
feature_count
print
"
Travelled %s meters
"
%
route_summary
.
distance
print
"
It took %s seconds
"
%
route_summary
.
elapsed_time
print
(
"
Finished trip with %s points
"
%
route_summary
.
point_count
)
print
(
"
Passed %s features
"
%
route_summary
.
feature_count
)
print
(
"
Travelled %s meters
"
%
route_summary
.
distance
)
print
(
"
It took %s seconds
"
%
route_summary
.
elapsed_time
)
def
generate_messages
():
...
...
@@ -105,7 +107,7 @@ def generate_messages():
make_route_note
(
"
Fifth message
"
,
1
,
0
),
]
for
msg
in
messages
:
print
"
Sending %s at %s
"
%
(
msg
.
message
,
msg
.
location
)
print
(
"
Sending %s at %s
"
%
(
msg
.
message
,
msg
.
location
)
)
yield
msg
time
.
sleep
(
random
.
uniform
(
0.5
,
1.0
))
...
...
@@ -113,19 +115,19 @@ def generate_messages():
def
guide_route_chat
(
stub
):
responses
=
stub
.
RouteChat
(
generate_messages
(),
_TIMEOUT_SECONDS
)
for
response
in
responses
:
print
"
Received message %s at %s
"
%
(
response
.
message
,
response
.
location
)
print
(
"
Received message %s at %s
"
%
(
response
.
message
,
response
.
location
)
)
def
run
():
channel
=
implementations
.
insecure_channel
(
'
localhost
'
,
50051
)
stub
=
route_guide_pb2
.
beta_create_RouteGuide_stub
(
channel
)
print
"
-------------- GetFeature --------------
"
print
(
"
-------------- GetFeature --------------
"
)
guide_get_feature
(
stub
)
print
"
-------------- ListFeatures --------------
"
print
(
"
-------------- ListFeatures --------------
"
)
guide_list_features
(
stub
)
print
"
-------------- RecordRoute --------------
"
print
(
"
-------------- RecordRoute --------------
"
)
guide_record_route
(
stub
)
print
"
-------------- RouteChat --------------
"
print
(
"
-------------- RouteChat --------------
"
)
guide_route_chat
(
stub
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment