Hi! I'm Heidi.I'm trying to build an api with python.I try to build with grpc.Post the image file to grpc server.The gprc server detects the object by deep-running the requested image file.First question: How do I transfer an image file to the server?
Show me an example.For example, when sending a string:response = stub.SayHello (helloworld_pb2.HelloRequest (name = 'you'))Second question. I want to request grpc server concurrently, not sequential. What should I do?I run one server .py. Then I run client.py at the same time. But it seems to be running sequentially.For example, one client.pySecond question. I want to request grpc server concurrently, not sequential. What should I do?I run one server .py. Then I run client.py at the same time. But it seems to be running sequentially.For example, it takes 1 second to run one client.py.But if you run 3 client.py at the same time, it takes 3 seconds.I want to know how to set up grpc worker or thread. Please let me know python code example.
--
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+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@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/ddcb37cd-371c-41c7-af3c-1ede967f8046%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
------------------------------------------------
from concurrent import futures
import time
import os
import grpc
import helloworld_pb2
import helloworld_pb2_grpc
## my function
from my_function import my_class
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
class Greeter(helloworld_pb2_grpc.GreeterServicer):
def SayHello(self, request, context):
## run function
a = my_class().detect_face()
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=20))
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
server_port = os.environ.get('PORT', 50051)
server.add_insecure_port('[::]:' + str(server_port))
server.start()
print("==== SERVER RUNNING =====")
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)
if __name__ == '__main__':
serve()
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@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/2e5ccc67-4e78-4147-8eec-ac386743fc05%40googlegroups.com.
def SayHello(self, request, context):
## run function
a = my_class().detect_face() ##<<I printed a pid, which has the same pid.
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
Thanks for the reply.As you said, I confirmed that it runs concurrently through the time.sleep () function.It seems to run concurrently internally.However, adding the function below is not simultaneous.I printed a pid, which has the same pid.---- server.py -----------------------------------------------------------def SayHello(self, request, context):## run function
a = my_class().detect_face() ##<<I printed a pid, which has the same pid.return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)----------------------------------------------------------------------------Where should I add my own functions? Please help me.helloworld_pb2.py ?, helloworld_pb2_grpc.py?
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@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/7e350547-7de0-4711-835a-0e724c822c82%40googlegroups.com.