gRPC定时任务完整实例代码 - server
import grpc
from grpc import status
from time import sleep
class MyService(grpc.Servicer):
def SayHello(self, request, context):
return grpc.StatusCode.OK, b"Hello, World!"
def main():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
server.add_insecure_port('[::]:50051')
channel = grpc.insecure_channel('localhost:50051')
with channel.insecure_connect() as sock:
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10), grpc.method_async_unary('SayHello', MyService(), sock))
server.start()
try:
while True:
print("Waiting for incoming messages...")
time.sleep(1)
except KeyboardInterrupt:
print("Shutting down the server gracefully...")
server.stop()
server.wait_for_termination()
print("Server stopped.")
if __name__ == '__main__':
main() 拼多多帮助力入口
MyServiceSayHello