1 Star 0 Fork 1

zhufeng/grpctest

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
service.py 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
zhufeng 提交于 2017-06-12 11:05 . first commit
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from concurrent import futures
import time
import grpc
from protos import helloworld_pb2
from protos import helloworld_pb2_grpc
from models import session, User
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
class Greeting(helloworld_pb2.GreetingServicer):
def CreateUser(self, request, context):
print str(request)
name = request.name
user = User(name=name)
session.add(user)
session.commit()
return helloworld_pb2.UserResponse(errcode=0, errmsg='ok', user_id=user.id)
def SayHello(self, request, context):
id = request.id
user = session.query(User).filter(User.id == id).one()
return helloworld_pb2.HelloResponse(message='Hello, {0}'.format(user.name))
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
helloworld_pb2_grpc.add_GreetingServicer_to_server(Greeting(), server)
server.add_insecure_port('[::]:50051')
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)
if __name__ == '__main__':
serve()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zhufeng9282/grpctest.git
git@gitee.com:zhufeng9282/grpctest.git
zhufeng9282
grpctest
grpctest
master

搜索帮助